How To Link To A Frame Adobe Flash CS6 Action Script 3 - actionscript-3

i need help with my adobe flash assignment , i m still new to adobe flash :( how to tell the user if they input the wrong keyword how to link them to a frame .
var i:int = 0;
var names:Array = new Array("html","head","body");
var frames:Array = new Array("6","7","8");
searchhtmlll.text ="";
searchhtml.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);
function fl_MouseClickHandler_2(event:MouseEvent):void
{
findInArray(searchhtmlll.text);
gotoAndStop(frames[i]);
}
function findInArray(str:String):int
{
for(i = 0; i < names.length; i++)
{
if(names[i] == str)
{
return i;
}
}
return 0;
}

I am answering based on whatever limited information you have provided in your question, and from what I understand.
Your method findInArray has a return type of int, where as you are just calling it without assigning it to a variable.
So your code should be:
var result:int = findInArray(searchhtmlll.text);
gotoAndStop(frames[result]);
Hope this helps.

Related

send json data to array(movieclip) as3.0

I am building an air app in flash cs6 using as3. I need to send a json to movieclip. I wanted to create a "timeline" on my application.
This is the code I use.
function onCompleteLoadTimeline(event:Event){
var result:Object = JSON.parse(event.target.data);
var yPos = 0;
for (var h:int=0; h<=1; h++){
tpost = new t_post();
tpost.x = 0;
tpost.y = 0;
timeline_mc.addChild(tpost);
timeline_container.push(tpost);
timeline_container[h].y = yPos;
yPos += timeline_container[h].batas.y;
}
for (var i:Object in result){
for (var j:int=0; j<=1; j++){
timeline_container[j].nama.text = result[i].timeline_name;
timeline_container[j].postingan.text = result[i].timeline_post;
}
trace ("nama : "+result[i].timeline_name);
trace ("status : "+result[i].timeline_post);
trace ("waktu : "+result[i].date);
trace ("suka : "+result[i].likers);
}
}
for the code only the latest data appear in the movie clip.
please help me.
You have a few for loops that go up to 1. I don't know what they are for.
The only loop that you need is the one iterating over the result.
var result:Object = JSON.parse(event.target.data);
var yPos = 0;
for (var i:Object in result){
var tpost:t_post = new t_post();
tpost.y = yPos;
timeline_mc.addChild(tpost);
tpost.nama.text = result[i].timeline_name;
tpost.postingan.text = result[i].timeline_post;
yPos += tpost.height + 10;
}
I have no idea what batas means (use English in your code!) which is why I created the logic to position the objects myself. If yours worked for you, just use that.
I also omitted the array code for brevity.
Btw: You are essentially building a custom component with a custom way to display data which is often referred to as an "item renderer". Go ahead and search for that term if you don't want to build everything from scratch.

Arranging items in an inventory

I'm working on an inventory system I made following a short tutorial that leaves you stranded. I've managed to get the items removed and rearrange to the correct order somewhat. For some reason though, if I click on the last item in my inventory, then on the first item, the items do not rearrange correctly.
public class Inventory {
var itemsInInventory:Array;
var inventorySprite:Sprite;
var itemNum:int;
public function Inventory(parentMC:MovieClip) {
itemNum=0;
itemsInInventory = new Array();
inventorySprite = new Sprite();
inventorySprite.x = 50;
inventorySprite.y = 360;
parentMC.addChild(inventorySprite);
}
public function makeInventoryItems(arrayOfItems:Array){
for(var i:int = 0; i < arrayOfItems.length; i++){
arrayOfItems[i].addEventListener(MouseEvent.CLICK, getItem);
arrayOfItems[i].buttonMode = true;
}
}
public function getItem(e:MouseEvent){
var item:MovieClip = MovieClip(e.currentTarget);
itemsInInventory.push(item);
inventorySprite.addChild(item);
item.x = (itemsInInventory.length-1)*40;
item.y = 0;
item.removeEventListener(MouseEvent.CLICK, getItem);
item.addEventListener(MouseEvent.CLICK, useItem);
}
public function useItem(e:MouseEvent){
var item:MovieClip = MovieClip(e.currentTarget);
itemNum = item.x;
inventorySprite.removeChild(item);
itemsInInventory.splice(item, 1);
sortInventory();
}
public function sortInventory(){
for(var i:int = 0; i < itemsInInventory.length; i++){
if(itemsInInventory[i].x > itemNum){
itemsInInventory[i].x -= 40;
}
}
itemNum=0;
}
}
I belive thats all the coding info I need to provide for help solving this mystery.
Also, a link to the game for testing. If you would like a link for a download of the game, please ask.
LINK
Instead of substracting 40px, just set their position again:
for(var i:int = 0; i < itemsInInventory.length; i++){
itemsInInventory[i].x = i*40;
}
Also, I did not even know that it is possible to give an object reference to the splice function, I would rather use:
itemsInInventory.splice(itemsInInventory.indexOf(item), 1);
And remove the event listener from the item when you delete it from the inventory in the useItem function.
item.removeEventListener(MouseEvent.CLICK, useItem);
EDIT:
With Flash Player 10, Adobe introduced the Vector class which is kind of the same as the Array class, but it can only store one data type. In your case it would be MovieClip or Sprite. The Vector class is singificantly faster and more developer friendly because you can see the help from the IDE when you are typing myVector[i].. I recommend using that instead, although there is nothing wrong with Array. It is just outdated a bit, but is helpful when you want to store more data types.
myVector:Vector.<MovieClip> = new Vector.<MovieClip>();

AS3 Textfield Whitelisting

So I have this chatting application that only allows users to say specific words in an array (whitelisting). I really need some help creating a function to check each word, and replace those with "###" that are not in the whitelist. I have an external Dictionary.txt file, but I also have an array set up in the code (whitelist).
Please help me out! Thanks
this is the simple way i can imagine it
var words:Array = ["test", "fu--"];
//
function dicionary(word:String) {
for (var i:Number = 0; i < words.length; i++) {
if (words[i] == word) {
trace ("####");
}
}
}
//
dicionary("fu--");
dicionary("Hello");
Hope it helps
EDITED
even better like this, because now it can replace words within sentences
var words:Array = ["test", "fu--"];
//
function dicionary(word:String) {
for (var i:Number = 0; i < words.length; i++) {
word = word.split(words[i]).join("####");
}
return(word);
}
//
trace(dicionary("fu-- I was wrong!"));
trace(dicionary("Hello"));

Flash action script3 problem, can't change property name

i'm not very good at AS3, but i imported XML to my flash and i want to change it dynamically from drop down menu. I need to change "THISPLACE" in script below with simple string, how do i do that? Thanks for help :)
function uzkrautXML():void
{
var XMLURLLoader:URLLoader = new URLLoader();
XMLURLLoader.load(new URLRequest(xmlArdesas));
XMLURLLoader.addEventListener(Event.COMPLETE, processXML);
}
function processXML(event:Event):void
{
var theXMLData:XML = new XML(XMLURLLoader.data);
visoSk = theXMLData.THISPLACE.length();
for (var i:Number = 0; i <visoSk; i++)
{
skArray.push(theXMLData.THISPLACE[i]);
}
uzkrautSkelbimus();
}
I know there are mistakes in code, but dont mind it, i need to know just how replace that plase
You can use child() method of top level XML class.
function processXML(event:Event):void
{
var theXMLData:XML = new XML(XMLURLLoader.data);
theXMLData.ignoreWhite = true;
visoSk = theXMLData.child("THISPLACE_NAME").length();
for (var i:Number = 0; i <visoSk; i++)
{
skArray.push(theXMLData.child("THISPLACE_NAME")[i]);
}
uzkrautSkelbimus();
}
Hope this helps.

How to Convert one Vector Data to another Vector Data in Actionscript 3.0

Class ShootGame implements IGame
{
}
//ShootGame Vector
var shootGames:Vector.<ShootGame> = new Vector.<ShootGame>();
for(i=0;i<20;i++)
{
shootGames.push(new ShootGame());
}
var igames:Vector.<IGame> = //What is the Simplest method to convert ShootGame to IGame Vector
//I am doing like
igames = new Vector.<IGame>();
for(i=0;i < shootGames.length;i++)
{
igames.push(shootGames[i]);
}
There is a more convenient way to do that.
var igames:Vector.<IGame> = Vector.<IGame>(shootGames);
Notice that when you use "Vector.< IGame >(shootgames)" you are not making a typecast, instead you are creating a new Vector instance and populating it with the content of the "shootGames" Vector.
For more detailed information, go here.
Sample code:
var shootGames:Vector.<ShootGame> = new Vector.<ShootGame>();
for (var i:int = 0; i < 20; i++) {
shootGames.push(new ShootGame());
}
var igames:Vector.<IGame> = Vector.<IGame>(shootGames);
trace("shootGames.length", shootGames.length); //20
trace("igames.length", igames.length); //20