ActionScript 3.0 :: Run A Function On Each Item Inside An Array?
Jul 23, 2009run a function on each item inside an array, and then remove it from the array, but only if one of its properties reach a certain number.
View 3 Repliesrun a function on each item inside an array, and then remove it from the array, but only if one of its properties reach a certain number.
View 3 RepliesHow can I target a movieclip that is inside each item in the array using getChildByName. Heres my code so far:
var aMC:Array=new Array(letter, envelope, parcel);
if(i< aMC.length){
var myTargetName:String = aMC[i].target.name;
var myTarget:DisplayObject = getChildByName(myTargetName);
trace("Stamps Target: "+myTargetName);
if (evt.target.dropTarget != null && evt.target.dropTarget == myTarget) {
// do what ever here
i++;
}}
I'm trying to run a function for each item in an array but I don't want it to happen all at once. The end result is to fadein an item in an array then fade it out, then move on to the next item in the array and do the same thing.
i guess in simple form I could demonstrate this with just using text:
Code:
myFunc = function(theGreet){
trace(theGreet);
}
[Code]....
I have the problem with creating multiply functions. I want to create onRelease function for every item in array that will navigate to specific URL from xml.Here is the code:
for(var i=0;i<numOfItems;i++)
{
var t = home.attachMovie("item","item"+i,i+1);[code]....
The problem is that the trace for url will work if I put nodes[0] for example instead of [i].
I want to be able to select an item from my list component and fire a function directly related to selecting that item. list is called "tidlist" function is "selecttid(n)" the "n" needs to be replaced with the index number... so if run my swf and the list component displays my items... when i select one (the third one for example)... i want to fire "selectTid(3)".... cant seem to grasp.
View 1 RepliesI want to be able to select an item from my list component and fire a function directly related to selecting that item.
list is called "tidlist"
function is "selecttid(n)"
the "n" needs to be replaced with the index number... so if run my swf and the list component displays my items... when i select an item (the third one for example)... i want to fire "selectTid(3)".... cant seem to grasp.
I put my mc's in an array.I have another array with strings.when the mc is clicked I want to get its position in the mc array and return the string from the same position in the string array.How do I do that?
PHP Code:
var numBtnArray:Array = new Array;
function addNumButtonsToStage():void{
[code].....
I know how to remove duplicates from an array, but what I'm trying to do is prevent an item from ever being added to an array in the first place if it already exists. I'm pulling in data from an xml feed in a loop, and I thought that searching for that values index would work, but no matter what, the index is always -1. Here's my code:
[Code]...
Maybe I'm misunderstanding the indexOf function, but I thought it was supposed to return -1 if a value did not exist in an array. What am I doing wrong?
I have this code to try to acess the values of the array in the arraycollection but it does not work it actually creates a value to the end of the arraycollection. can anyone tell me what im doing wrong i basically whant to modifys the individual arrays in the arraycollection and add Login_user.
Code:
for(var i:int = 0; i< dispArray.length; ++i){
dispArray.addItemAt({"login_user":"XXX"},i);
}
i'm trying to make an xml menu but i'm stuck on this spot and just can't get around it.i have this xml file:
Code:
<?xml version="1.0" encoding="utf-8"?>
<menu>[code]..........
And , as u can probably see, it's a menu with 3 buttons, and the middle one is supposed to have a submenu.I am looping through the menu items and it displays everything alright:
ActionScript Code:
var xml:XML = new XML();
var total:Number;[code]..........
What i can't figure out is the piece of code needed to count the nodes inside the <item> tag.
I have a code like this:
<mx:Repeater id="allItemRepeator"
dataProvider="{_model.allItems}"
>
<components:ComponentSelector id="componentSelector"
[Code]....
When code changes for allItems the item disapears from screen as expected but still sits in memory! I know this by a function inside a compoenent that has "trace" so the trace output still displays even after the component disappears from screen. How do I ensure that the element is deleted when it's reference is deleted? Will using List-based component to display items instead of "Repeator" solve the problem (it requires significant refactoring of my code so I'm asking before trying it out)
I have done this same thing in ActionScript 3, but am not familiar with ActionScript 2, which I am forced to use for this project. I am loading products into a SWF via XML and attempting to add a click event to each dynamically-created movieclip. Simply tracing the text from a node in XML will do for now. I'd like to assign a property called "desc" or "description" to each movieclip and have it trace that property's value when clicked. Here is the relevant portion of my code as it stands:
ActionScript Code:
var iXML:XML = new XML();
iXML.ignoreWhite = true;
[Code].....
I have an Item Renderer having HBox. Now I want to add child in that HBox from my application file using addChild method. Any way around for the same. I am not able to access the properties of HBox inside the item renderer.
View 1 RepliesI want to know if there is a method or some code to add new items to an array, but it want the items have the name of the buttons's instance name, or the label's name, so when i push the button, it adds its name to an array. Here is my code:
ActionScript Code:
tauri.addEventListener(MouseEvent.CLICK, addAddress);
abydos.addEventListener(MouseEvent.CLICK, addAddress);
tollana.addEventListener(MouseEvent.CLICK, addAddress);
dialNow.addEventListener(MouseEvent.CLICK, dialTo);
var tauriAddress:Array = ["tauri","abydos"];
var newAddress:Array = new Array();
function addAddress(event:MouseEvent):void {
newAddress.push();
I don't know if I should use the push method here, tell me what to put here for adding the instance name of the button to the array
trace(newAddress);
}
below is my script,to sum up the number in my array....but the output is all the numbers in array and not the sum up numbers....
CorrectMark =correctArray[0]+correctArray[1]+correctArray[2]+ correctArray[3]+ correctArray[4];
display.text=CorrectMark;
I'm trying to add an item to an array, but when I do, it keeps the results (prizeField) from before and adds the new ones to it. i.e. at the beginning if I push a string to the array I have 4 items. If I push another, I then have 9. Then 15 and so forth. Here is my code:
Code:
var myFlexParent:Object;
var prizeArray:Array = ["apples", "bananas", "cranberries"];
var textFormat:TextFormat = new TextFormat("Cairo", 48);[code].....
I know that I need some sort of removeChild() in there, but I cannot get it to actually work.
Actionscript Code:
<root><node><child><grandChild></grandChild></child></node></root>
Actionscript Code:
Arr[0]=rootArr[0][0]=nodeArr[0][0][0]=childArr[0][0][0][0]=grandChild
Help needed to create Multidimensional Array from Recursive XML.
All I need create Array inside an Array dynamically from an unknown XML tree.
When the combo box is changed it will add items to another combo box, i.e if africa is chosen, all the countries in africa will be listed in the second combo box.
At the moment i am manually adding in all the countries, _root.combo1.addItem("Label", "Data");
for 60 countries that would be messy code, is there a way to do it in an array cause my advanced actionsript isnt that good. But i will need to be able to get the data of a country out later ....
Hw to add an item to the front of an array? this works fine, but not sure if its the most "poetic" code around.[code]...
View 2 RepliesI have one array with items. now I want to remove all items from array. How it can be possible ?
View 7 RepliesI have a tricky problem in that I have an array that has been populated with strings ("item1", "item2", etc). However, at a certain point I need to pull one randomly out of the group, via a random number function. The issue is I cannot reference the items in the array by a number, I get an error. So when I try to get myArray(5) it doesn't work.
How can I work around this so I can grab a random item in my string array?
var arr1:Array = new Array();
arr1.push(item1);
arr1.push(item2);
arr1.push(item3);
then arr1 and its elements get passed to other functions is there a way to know the index of an item in the array?
GetParentArrayIndex(item2) would give me 1;
I have 2 arrays & 2 checkbox repeaters: the second gets populated w/ items selected from the first. I can add the items no problem. How do I then delete the item if it gets deselected from the first checkbox repeater?
[Code]....
I have two two-dimensional arrays, and this line of code:
openListParents[compWith] = openList[olID];
Does it work? Yes. However, openListParents[compWith] becomes openList[olID], but I want openListParents[compWith] to be the value of openList[olID]. This is what I get when I press CTRL+ALT+V:
[Code].....
This is because openList might change, and I want the value of that openListParents in the array to be the value of the openList at the time when the code is run.
If I have a list of items in an array that represent the names of modules:
[Code]...
I have an array of questions for an interactive quiz game. When you answer a question, functionally I want that question to be removed from the array (cat4Questions) so that it won't come back for the player so I tried to splice it.I wasn't sure if it was working so I traced the array. While I was expecting "question1, question2, question3, question4" to be traced, "question1, question2, question3, question4, question5" was the result of my trace.This is the line of code where I try to splice the array:cat4Questions.splice(cat4Questions.length,1);trace(cat4Questions);
View 3 RepliesHow do you specify a certain item to be removed from an array?I know how to remove an item of a certain position, for example:
array.splice(1,0)
BUT, if I have an array with the following items:
1,2,3,4,5,6,7
and I want to remove the item "4" without referring to its position, is there a way to do this?
What I have: 2 buttons on stage (NEW_YORK and CHICAGO) which are given an onRelease function trough a forLoop (so far so good).
What I need: For those to buttons to trace their own array item when i press them.
The problem: If I summon the array item static (array[1]) it works, but when i try to make it dynamic (array[i]) it comes back as undefined.
I enclosed the .fla.[code]...
So I'm getting strange results when trying to remove the first item in my array. When I remove the first item by using the shift() method, it deletes the whole array instead of just the first item.
Here is my code.
Code:
public class Main extends MovieClip
{
var deck:Array =
[Code]....
When I run the program it correctly shuffles the deck array and pushes all the shuffled items into the shuffledDeck Array. Then the first 26 cards get pushed into the playerDeck Array and the rest go to the computerDeck Array.
When the last bit of code runs, it correctly picks the first item in the playerDeck Array, but when I try to remove that item, it removes everything in playerDeck.
i am tring to check the values imn my array but for some reason the hit is never trace. So is the value o0f cat not found in the array. if not what do i do to find the value cat
ActionScript Code:
var numbers_array = new Array("cat");
for( i =0; i < numbers_array.length; i++){
[Code]......