Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Dynamic Array



I've got a .fla with a MC that creates a new array in the load evernt handler.


Code:
onClipEvent (load) {
var myArray = new Array(0,30,60,90);
}


What i want to do though, is have the values inside the array, created dynamically at run time. Is this possible ?

Bascially the values in the array are going to be the _x values of other MC's on the stage.

I tried feed variables strati into the arrary ..

var myArray = new Array(mc1x, mc2x ... etc); but that doesnt read the values ?

ANy ideas ?



FlashKit > Flash Help > Flash ActionScript
Posted on: 06-15-2001, 06:21 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Dynamic Array/change Array Size At Run Time
how can i make a dynamic array
so i can change its size at run time
add and delete values fom the array
and his size will change as needed
10X
peleg

AS2 : Using Variables As Array Names/ Dynamic Array Names
Hi,

Hoping someone here can help me with this problem:-

This code works (as part of a loop):-

attachMovie(x1r1[i], "Aln1" + i, i);

where x1r1 is the name of an array which gets cycled through.

However, this array name will change on a new level, (lvl) so what I really
need is something that works like this:-

lvl = 1;
var ex = "x"+lvl"+r1"
attachMovie(ex[i], "Aln1" + i, i);

However flash does not see ex as equal to "x1r1" for the purposes of
using it as an array name. Not even if I use "eval".

Any suggestions?

Thanks

Michael.

Dynamic Array (MX)
Greetings,

I'm trying to create a named array using a variable name. Rather than try & explain all of this, here's a quick sample. If somebody could give me some pointers - I'll really appreciate the help!

Thanks!

var operatorID= "13";
var theName="Mason";
var arrayName="operator"+[operatorID];

arrayName =new Array();

arrayName.name=theName;

trace("arrayName.name= " +arrayName.name); //shows value

trace("operator13.name"+operator13.name); // does not show value - how to i reference this after i've created it?

How To Get Array Through Dynamic Name?
Hi. I have a few arrays. Let's say they are:

bracelets
necklaces
ties

How would I fetch data from within one of those arrays, if the array's name is passed in by a variable (items)? I tried everything I could think of, such as this:


Code:
function displayMenu(items) {
j=[items].length;

for (i=0; i<j; i++) {
duplicateMovieClip("Holder",i,i+100);
product = [[items][i]];
loadMovie("products/"+product+"_60.jpg", i);
}
}
}
See the name is passed in by "items", and then I want to be able to get the data, the same way I would this: bracelets[i] but the word "bracelets" can change. It's determined by "items".

??!?

Dynamic New Array()
hi there.

I have the following problem:

i've got a variable, let's say 'temp'.

In a function i want to create a new Array named variable 'temp' + '_array'


eval(temp)+"_array" = new Array(); -- does not work.



who can help me out???? thnx

Dynamic Array Name?
Hi, im trying to set the name of an array on the fly but i cant seem to get it to work: i have simplified this so it makes more sense. This is basically what im trying to do. I have tried using eval but no joy.


Code:
currentProduct = 1;
basketID = this["basket" + currentProduct + "Data"]
var basketID:Array = new Array("Name", "Code", "Price", "active");
trace(basketID); // traces the array
trace(basket1Data); //traces undefined


// var [basketID]:Array = new Array("Name", "Code", "Price", "active");// doesnt work


// var this["basket" + currentProduct + "Data"]:Array = new Array("Name", "Code", "Price", "active");// doesnt work either
Can anyone tell me what im doing wrong? Please!
Cheers
Neil

Dynamic Array
I'm trying to build a for loop from an array (for a sound object) where I create a name based on a name + i (from for loop). I can't quite get it to work. If anyone has any thoughts about this, it'd be greatly appreciated. Here is the code which isn't quite working.

for (i=0; i<sentenceArray.length; i++) {
sound_sentence[i] = new Sound(this);
sound_sentence[i].attachSound(sentenceArray[i]);
}

In theory I'd this to play appropriate sound based on for loop above however it is not working:
sound_sentence0.start(); //play 1st sound in array
sound_sentence1.start(); //play 2nd sound in array...etc

Any help would be great! Thank you!

Andrew

Dynamic Array
I am looking to explore the idea of a gallery that has a drag and drop functionality.. i have the drag and drop ready to go... with a holder movie clip..
the next step in my grand plan is to create an array of images that is loaded externally via xml i suppose.. the array will be called "mc" and would contain a list of jpgs (it could have anywhere from 1 - 10 images in it)

can some one point me in the right direction for creating the xml and then having my swf load it and turn it into an array called "mc"

i'll love you for ever!

Dynamic Array
Hello
I am trying to pass some variables to an array.
If you have any idea please help.


Code:

function Picture (picName, link, picColor, description) {
this.picName = picName;
this.picLink = link;
this.picColor = picColor;
this.description = description;
}

pics = new Array();
myData = new LoadVars()
myData.load("flash_used_cars.php")
myData.onLoad = function(success){
if(success){

for (var k = 0; k<myData.total; k++) {

text1 = myData["model"+k];
text2 = myData["date"+k];

link = myData["path"+i];

pics[k] = new Picture(text1, link, 0xFF9999, text2);

}


} else mess.text = 'error';

}

for (var i = 0; i<pics.length; i++) {
newCell(i, pics[i]);
}

Dynamic Array In FMS
Ok, I have a problem, a not so big problem, but a problem. :/

I have this array that is dynamic for FMS.
ActionScript Code:
[Client.name + "Idea"] = new Array(idea1,idea2,idea3);

Except, for some reason, it won't work unless i put a this infront of it so it becomes this:

ActionScript Code:
this[Client.name + "Idea"] = new Array(idea1,idea2,idea3);

It works fine for everything, except I have a separate function that needs to update the first string, eg:

ActionScript Code:
[username + "Idea"][0] = newIdea;

but as you can imagine, it gives me errors if I don't put the this infront of it:

ActionScript Code:
this[username + "Idea"][0] = newIdea;

But, then it doesn't update. Why? I'm not so sure, but probably because the array level is different (one is in the root, and one is in function), and I have tried using _parent, _global, and _root to access it, but anything with _ in it gives me not defined errors.

Does anyone have an idea what I could do. :yoshi:

Dynamic Array
How can I load an Array thru XML or TXT?

Dynamic Array
I am getting values from a URL, and they are:

date_1=0&date_2=0
and so on up to date_20

Using this:

ActionScript Code:
for(i=1;i<21;i++){
    count[i] = eval("this.date_"+i+";");
    trace(count[i]);
}

when I trace the value, I get undefined why?

Dynamic Array
I got an array like :

// RECORDING DATA
var my_array:Array = new Array();
my_array.push({id:2, myPassword: "Bob", age:29});
my_array.push({id:1, myPassword: "John", age:30});

// RETURNS RESULTS
for(i=0;i<my_array.length;i++){
trace(my_array[i].myPassword);
}

But, I use dynamic variables, so I wrote :

myData = "id:2, myPassword: "Bob", age:29";
my_array.push({myData});

Of course it doesn't work !
It can't find my vars name id, myPassword...
It takes ereverithing as one String !

I tried another way to made it but it's failed too :
myData = "{id:2, myPassword: "Bob", age:29}";
my_array.push(myData);

Any idea ?
Thanks

Dynamic Array
How can I load an Array thru XML or TXT?

Dynamic Array
Is it possible to create an array on the fly using action script?

My dilema is: Let's say I had a group of movieClips created using duplicateMovieClip, and each one of them had a unique name (created in a for loop).

Is it possible to have the user click on each mc and create a unique array name corresponding with that movie clips instance name?

In the application I'm building there may be at any given time a unique number of arrays with unique names.

I hope that made some sort of sense.
Thanks

Dynamic Array Name
Hi,

Im trying to run an IF statment which accesses an array by a dynamic call....

basically my call is

if ("line" + givenLine + "[" + i + "-1]" == "line" + givenLine + "[" + i + "]"){

I am trying to access the ARRAY 'line1' or 'line2'

therefore the value of givenLine is dynamic, however this seems to be just creating a string rather than understandable actionscript - eg line1[0]

Any ideas

Thanks

Dynamic Array Access
Hi,

I'm trying to take a sentence and break it into an array of words (done) then take the words and break them into arrays of letters. I was able to do a sloppy bit of code and make a buch of variable but I'd kinda prefer to do it with arrays cuz it's a whole lot cooler.

anyway here is the mucked up code for the variable generation just so you can see what I was trying to do

on (release) {
words = v_1.split(" ");
for (i=0; i<words.length; i++) {
for (l=0; l<words[i].length; l++) {
set ("word"+i+"["+l+"]", words[i].charAt(l)
);
}
}
}

and here is the array generation code as it stands now

on (release) {
words = v_1.split(" ");
for (i=0; i<words.length; i++) {
set ("word"+i, []
);
for (l=0; l<words[i].length; l++) {
set ("word0"+[l], words[i].charAt(l));
}
}
}

I can create the arrays OK but it's the last line of code where I try to populate them that's not working - where it says "word0"... I had tried "word" + i + [l] and it disregards the [] so it I know there is something I'm doing wrong with the syntax

Thanks to all who give this some thought
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Array To Dynamic Text - Pls Help...
Hi

Does anybody have an idea how to put "n" number of array elements into dynamic text boxes?

I have an array with dynamic number of elements:

arr[0]=3;
arr[1]=21;
...
arr[n]=13;

I will need two things:

1. How can I create a specific number of dynamic text fields which depends on the number of array elements (arr.length)?

2. How can I put the value of the array element to dynamic text? I tryed to put arr[0] in variable field but it doesnt work..

Help me please!

cheers

michal

Dynamic OnRelease From Array
For some reason, this won't increment. imageFileName is an array of images. I should be able to assign onRelease functions to duplicated buttons in this manner, but for some reason the counter inside the onRelease function isn't incrementing. What the *&*%%$!?


Code:

function buttonActions() {
length = imageFileName.length;
trace("IMAGEFILENAME CONTAINS " + length + " KEYS.");
for (i=0; i<=length; i++) {
trace("I want to assign this key to button " + i + ": image" + i);
trace("thumb"+[i]);
trace("THE IMAGE NAME : " + "/images/image" + i + ".jpg");

// The 'i' variable inside this function won't increment , even though it's inside the loop!!
_root["thumb"+i].onPress = function() {
trace("/images/image" + i + ".jpg");
loadMovie("/images/image" + i + ".jpg", _root.JPGtarget);
}
}
}

Vars To A Dynamic Array
Can anyone tell me if its possible to build an array based off of random variables loaded into the movie using loadvars ?
For example if i have a text file containing:

&dog=3;
&cat=14;
&phone=9;

when i load it i would like an array to be dynamically built that would be equal to this:

randomvars = {dog:3, cat:14, phone:9};

Any help is appreciated
thx

Dynamic Textbox And An Array
I have several Arrays populated with data from a RSS feed. I would like the dynamic text boxes I have embedded in a MC to filled by data from the arrays and change to the next node in the array every minute.

I am a complete newbie to flash and actionscript and have had a lot of help to get this far.

Any help would be greatly appreciated!

Dynamic Associative Array
Does anyone know how to create a dynamic associative array. I also want to sort the array.

So instead of putting:

myArray.name = "whatever";

I want "name" to be a variable so I can make an associative array based on user input..

For sorting purposes I've tried analysing another associative array and making a new one from that using a for...in loop with:

myArray.[name] = Arrayname[name];

but that doesn't work..

Please help.

Dynamic Textbox To Array
Hi,

I'm trying to populate an array with numbers entered in a textbox by the user.

For example, the user enters numbers seperated by commas into the textbox and clicks a submit button. Each number then becomes an element of an array.

I know how to create and populate an array normally but have no idea how to do this.

Has anyone any ideas please?

Dynamic Slot In Array
Hi

I've got a problem that's got me perplexed.

I have an array with many levels eg:

array1(stuff,stuff,stuff)
array2(stuff,stuff,stuff)
array3(stuff,stuff,stuff)

_root.topLevel_array(array1,array2,array3)

I want to take topLevel_array[1] (or [0] or [2] not important which) and randomize its contents, which I can do no problems via a function that creates a new array temporarily holds the randomized array.
I then want to put that temporary array into the slot its contents came from.

So the code is:
TArray = _root.topLevel_array[1];
arrayLoc = "_root.topLevel_array[1]";
_root.randomizeArray(TArray, arrayLoc);

function randomizeArray(TArray, arrayLoc){
var temp_Array = new Array ();
var arrayLen = TArray.length;
for (var i = 0; i <= arrayLen; i++){
var arrayLen = TArray.length;
var ranIndex = Math.floor(Math.random()*(((arrayLen-1) - 0)+1))+0;
temp_Array.push(TArray[ranIndex]);
TArray.splice(ranIndex,1);
}
this[arrayLoc] = temp_array;
}

Except the last line doesn't work. It is meant to replace the contents of _root.topLevel_array[1] but doesn't.
I can't use eval() because that isn't allowed left of an = sign.
_root[arrayLoc] doesn't seem to work either.
Ideally I need to keep arrayLoc as a full path so that it doesn't matter what array is being randomized.

Can anybody out there help please?

Ta

Barry

Dynamic Text From Array
Hello everyone,

I'm having a problem creating textfields that will put the different values of an array into them. The textfields are inside a mc called heading + x (where x is a value from 1 to 8.) The heading mc's are in a mc called sectionstrip, and sectionstrip is in a holding mc called sectionholder. I am finding that there is no text appearing. I'm unsure if you can name textfields using a counting variable like you can with mc's.
i.e.
Code:
_root.sectionholder.sectionstrip["heading" + x].createTextField(["headingtext" + x],15000,100,100,50,100);


The rest of the code for that section is below (drawSquare is a function I created)
Any help would be greatly appreciated,

Cheers
Graeme





Code:
//the rest of the squares
// ----------------------

for(i=400;i<=3201;i+=400){
_root.sectionholder.sectionstrip.drawSquare(i,0,400,250,1,0x99999,0xFD0E02*((i/400)-1)/.25,25);

x = (i/400);
_root.sectionholder.sectionstrip.createEmptyMovieClip("heading" + x,(10000 + x));
_root.sectionholder.sectionstrip["heading" + x]._x = i;
_root.sectionholder.sectionstrip["heading" + x].createTextField(["headingtext" + x],15000,100,100,50,100);
_root.sectionholder.sectionstrip["heading" + x]["headingtext" + x].embedFonts = true;
_root.sectionholder.sectionstrip["heading" + x]["headingtext" + x].text = link(x);
};

Dynamic Array Problem
Hey all. I'm trying to get flash to buld an array on the fly. I've got the xml loading and the list of things I want in the array formatted properly. My question is how do I get Flash to "think" that what is there is structured like the code that is commented out?

The XML file is attached if anybody needs to see it.

Thanks,
Mike

code:
var swfXML = new XML();
swfXML.onLoad = buildArray;
swfXML.ignoreWhite = true;
swfXML.load("3114swfArray.xml");
function buildArray(success) {
if (success == true) {
var swfList = "";
for (var i = 0; i<swfXML.firstChild.childNodes.length; i++) {
var thisNode = swfXML.firstChild.childNodes[i];
swfNum = thisNode.attributes.value
var swfArray = "theSwf["+i+"] = "" + swfNum + ";"";
swfList = swfList + swfArray;
}
_global.theSwf = new Array();
swfList
} else {
trace("SWF Array Not Loaded");
}
}

/*
_global.theSwf = new Array();
theSwf[0] = "coa_00115";
theSwf[1] = "coa_00120";
theSwf[2] = "cia_00105";
theSwf[3] = "lia_01105";
theSwf[4] = "tpa_01105";

etc...
*/

Dynamic Array Names?
Please let me know if it's possible. I want to end up with several arrays like myArray1, myArray2, myArray3, etc. Here's a simplified version of what I want to work that will not.


Code:
onClipEvent(enterFrame) {
if (myVar==nul) {myVar=0;}
if (myVar<10) {
myVar++;
myArray[myVar] = new Array("thisVar", "thatVar");
}
}

Dynamic Array Path
Hello,

I am trying to build a recursive function which loops through an xml object to find all nodes, sub-nodes, sub-sub-nodes, etc.,

In order to do this, I need to be able to reference the nodes dynamically but they are coming up undefined when using eval()

For instance:

When I trace the actual path:
menuXml.firstChild.childNodes[0];
It returns the actual node without a problem

But when I trace this:
eval("menuXml.firstChild.childNodes["+0+"]");
It comes back undefined

Is eval incapable of returning arrays?

Any help is appreciated

Using Dynamic Text With An Array?
Is it possible for a dynamic text box to load it's input directly from an array, or would the value in the array have to be assigned to a variable first?

I have tried using 'myArray[1]' etc. in the 'Var' field in the properties of the dynamic text box, but it doesn't seem to work.

If this is not possible, what is the quickest way to load all the values of an array into individual variables? Using a 'for' loop?

Cheers,
Shiny

Dynamic Buttons, Array, And Url
Hi

i have 3 buttons that when pressed they will load in an image name test1.jpg and so on.


Code:

files = new Array();
var j = 1;
var l = 50;
for(i = 0 ;i < 3; i++){
files.push('test' + j + '.jpg')
trace (files[i]); // output = test1.jpg test2.jpg test3.jpg
this.attachMovie("submit",['mc_submit'+j], this.getNextHighestDepth());
this['mc_submit'+j]._y = l;
this['mc_submit'+j]._x = 450;
this['mc_submit'+j].onRelease = function (){
loadMovie(files[i],place);

}
l = l + 50;
j++;
}
everything works .....there are 3 buttons on the stage but they dont load in the image .....when i click it just says undefined

Dynamic Text From An Array
I'm trying to populate several dynamic text fields from an array, and it's not working. In the "var" field for the text field, I've entered the array name and element position (like: my_array[1]), but the text field stays unpopulated. If I change the "var" field to just a plain ol' variable name and define the variable, it populates just fine. Also, I know that the array itself is fine.

Any idea what could be going on, here? Am I going to have to make seperate variables for each member of the array?

-EdM.

Need Some Array Help W/ Dynamic Naming
I would like to know if there is a way to make this piece of code dynamic ex:
input1_txt, and yourAnswer1 would become whatever step you were on, if on step 2, yourAnswer1 would become yourAnswer2. but I also need to hold yourAnswer1 + the inputed info.

this is the code:
code:
input1_txt.onChanged = function() {
if (yourAnswer1 == correctAnswer) {
stepNum();
nextFrame();
} else if (input1_txt.text.length>=correctAnswer.length) {
assistant.alert.play();
}
};

I would just like to have this code once, and it would "count up" for each step you go to

input1_txt - is an input text field
yourAnswer1 - is the variable to hold the users input
correctAnswer - is defined in my xml
stepNum(); - is my function to display the step instructions
code:
stepNum = function () {
var z = stepCounter;
stepCounter++;
messageType = rootNode.attributes.Title;
theStepper = "Step "+stepCounter+" of "+maxSteps;
instructions = rootNode.childNodes[2].childNodes[z].attributes.TEXT;
stepScenario = rootNode.childNodes[2].childNodes[z].attributes.Scenario;
theScenario = rootNode.childNodes[1].childNodes[stepScenario-1].attributes.TEXT;
correctAnswer = rootNode.childNodes[2].childNodes[z].attributes.INPUT;
// trace ("step scenario number"+stepScenario);
};

right now I can hard code each input box, but that requires copying and pasting the code and changing the input1_txt and the yourAnswer1 for each input box, plus I have to declare all of the yourAnswer variables so they will hold the information, which isnt a problem, but can become tedious. I know with Arrays I can probably do this, but I can't get it to work.

make sense?

IMS

Array Of Dynamic Textfields?
Hi all,

I'm wondering if there's a way to do this...

I have seven values from an XML file that I'd like to display in seven dynamic textfields. I'd also like to do some processing on the text in those fields based on certain user input.

I was hoping that I could name my dynamic textfields things like myText[0] and then go through my XML data and do something like this:

myText[0] = myXML[0].attributes.name;
myText[1] = myXML[1].attributes.name;

(or using a For loop)

and so on but that doesn't seem to work.

Is there a way to do something like this without resorting to hard-coded dynamic textfieldnames and iterating through them by explicitly?

Thanks!

How Can I Set Dynamic Array Property?
I want to use this function multiple times but the array has different property name. i tried this[dynamicProperty] but get error..

PHP Code:




private function eregArray(arrayData:Array, filterName:String, dynamicProperty:String):Array {
    var regExp:RegExp;
    if (filterName == "All") {
        // do something
    }
    else if (filterName == "#") {
        // do something
    }
    else {
        // do something
    }
    if (filterName != "All") {
        for (var i:int = 0; i < arrayData.length; i++) {
            if (!regExp.test(arrayData[i].dynamicProperty)) {
                arrayData.splice(i, 1);
                i--;
            }
        }
    }
    return arrayData;
}

Dynamic XML Array Push ?
I'm having an issue with pushing the node contents of my XML to an array.
I'm real close and have tried a ton of things, but I'm hoping to get a push here..

The XML node looks as follows:


Code:
<coord>1,1,1,1,1,1,1,1,1,1,1,1</coord>
The as is as follows:


Code:
var myMap:Array = new Array();
myMap.push(new Array());
for (var n:Number = 0; n < mapInput.mapCoords.coord.length(); n++) {
var coordElementStr:String = mapInput.mapCoords.coord[n];
var tileCountWidth:String = mapInput.mapCoords.coord[n];
var tileWidthNumber:int = tileCountWidth.length;
myMap[0].push(new Array([parseInt(coordElementStr.charAt(0)), parseInt(coordElementStr.charAt(2)),
parseInt(coordElementStr.charAt(4)), parseInt(coordElementStr.charAt(6)),
parseInt(coordElementStr.charAt(8)), parseInt(coordElementStr.charAt(10)),
parseInt(coordElementStr.charAt(12)), parseInt(coordElementStr.charAt(14)),
parseInt(coordElementStr.charAt(16)), parseInt(coordElementStr.charAt(18)),
parseInt(coordElementStr.charAt(20)), parseInt(coordElementStr.charAt(22))]));
}
The above code works fine, but is limited to 22 chars...

I'd like it to parse the node regardless of length by first calculating the length and then looping through the push based on that int (tileWidthNumber).

Any thoughts?

It's important to ignore the commas from the node, and the push each value to the myMap array.

Thanks!

Dynamic Array Names
Hello, I am having an issue evaluating a variable in order to use it as an array. Here is the code


Code:
function cardsBuild(){
images1 = imagesArrayCreate();
images2 = imagesArrayCreate();

if (images1.length > 0 && images2.length >0){
arrayNum = randomNumber(1, 2);
trace("arrayNum = "+arrayNum);
arrayName = "image" + arrayNum;
} else if (images1.length > 0 && images2.length <=0){
arrayNum = 1;
arrayName = "image" + arrayNum;
} else if (images2.length <=0 && images2.length > 0){
arrayNum = 2;
arrayName = "image" + arrayNum;
}
trace("images1 = " + images1[0] + ", images2 = " + images2[0]);
trace("arrayName = " + [[arrayName] + "["+0+"]"] );
trace("arrayName = " + [[arrayName] + "[0]"] );

}
basically I am trying to use a random number to decide which array to use, but I am not able to evaluate the variable name in order to get the proper array index. Maybe I am going about it the wrong way, I would appreciate any advice. Thank you in advance.

Dynamic Array Of TextBoxes
I have a 100 text boxes I would to be able to change within a loop so I would like them to be defined as an array however it is not working correctly.

---------------------------------------------
for (i=1; i<=100; i++) {
TextBox[i] = i;
}

---------------------------------------------

I have each of my textboxes vars defined as TextBox[1]-TextBox[100]. Can someone tell me what the problem is or if there is a better way to do this. Thanks.

Dynamic Text Array
Hi there,

I have a series of 10 dynamic text fields with the instance names in the format:

insname1
insname2
insname3
...

What I want to do is to populate the fields from an array. How would I go about doing that in a for loop within the actionscript?

Any help would be appreciated as I am tearing my hair out!

Dynamic Array Keys
I am working on a small project for a few of my friends, and one aspect of the project requires me to create dynamic datagrids. That is the easy part.

The hard part is getting hte data formatted exactly how I want it. One thing that I would like to do is use dynamic array keys. In previous versions of AS, I have always done something like this. arrayName.push({thisKey + i:value}). However with as3, this is a bust.

Anyone know how this can be done?

Here is the snippet of code where I am having the issue. It is at the imgInfo.push.


Code:
for(var p:int = 0; p < resultArr.length; p++){
var dailyData:Array = new Array();
dailyData = resultArr[p].dailyData;
for(var n:Number = 0; n < dailyData.length; n++){
imgInfo.push({df:dailyData[n].adcl})
}
}

Dynamic Array Of Objects
Hi guys istuck

ActionScript Code:
var expenses:ArrayCollection = new ArrayCollection([
                                                {expenses:"Proteins",Amount:"30"},
                                                {expenses:"Vitamins",Amount:"20"},
                                                {expenses:"Carbs",Amount:"40"},
                                                {expenses:"Fat",Amount:"10"},
                                                ]);
how to create this array collection dynamic thats the values Amount
are dynamic and values to expenses are dynamic

Creating An Array With A Dynamic Name?
Hi, really struggling with this.

Say i have an array:
var myArray = ["cheese", "milk", "eggs"];

what i now want to do is loop through this array and create a new array for each element in myArray, so now i would have 4 arrays:

myArray:Array
cheese:Array
milk:Array
eggs:Array

i cant work out how to do it on the fly though, like
var this[myArray[i]]:Array = new Array();

do you see what im getting at? Its in a class if that makes any difference
help much appreciated!
Cheers, Neil

How To Access Dynamic Mc In An Array?
Hi,
I'm creating instances of a movieclip in the library dynamically, then i want to animate them (make them drop from the top to bottom). But I can't figure out how to access them in my array.

They are in there, they come up in a trace, but using a loop through them (on enter frame) and trying to change y value doesn't work? I have my array registered at the top of the class, and get no errors..


Code:
// randomly create treasures with timer (WILL MOVE TREASURES WITH TIMER ASWELL)
public function createTreasures(){


var rand:Number = (Math.ceil(Math.random()*2000))
var timer:Timer = new Timer(rand);
timer.addEventListener(TimerEvent.TIMER,timerF);
timer.start();

treasures = new Array();

function timerF(event:TimerEvent):void{

var treasure:MovieClip = new Treasure();
treasure.x = (Math.ceil(Math.random()*800));
treasure.y = 0;
//random treasure type
treasure.type = Math.ceil(Math.random()*5);
treasure.gotoAndStop(treasure.type);
treasure.speedY = Math.random() * 5 + 2;
treasure.inAir = true;
treasure.width = 20.0;
treasure.height = 40.0;
//keep treasures with min/max boudary
if (treasure.x<100){
treasure.x = treasure.x + 100;
}
else if(treasure.x>700){
treasure.x = treasure.x -100;
}
//add to stage
addChild(treasure);
//push into array
treasures.push(treasure);
}
}





//loop through treasures
public function moveTreasures(timeDiff){
for(var i:int=0;i<treasures.length;i++){


// add to treasures y value
treasures[i].y = treasures.y + 100;
}
}
http://www.actionscript.org/forums/i...s/rolleyes.gif

Dynamic XML Array Push ?
I'm having an issue with pushing the node contents of my XML to an array.
I'm real close and have tried a ton of things, but I'm hoping to get a push here..

The XML node looks as follows:


Code:
<coord>1,1,1,1,1,1,1,1,1,1,1,1</coord>
The as is as follows:

Code:
var myMap:Array = new Array();
myMap.push(new Array());
for (var n:Number = 0; n < mapInput.mapCoords.coord.length(); n++) {
var coordElementStr:String = mapInput.mapCoords.coord[n];
var tileCountWidth:String = mapInput.mapCoords.coord[n];
var tileWidthNumber:int = tileCountWidth.length;
myMap[0].push(new Array([parseInt(coordElementStr.charAt(0)), parseInt(coordElementStr.charAt(2)),
parseInt(coordElementStr.charAt(4)), parseInt(coordElementStr.charAt(6)),
parseInt(coordElementStr.charAt(8)), parseInt(coordElementStr.charAt(10)),
parseInt(coordElementStr.charAt(12)), parseInt(coordElementStr.charAt(14)),
parseInt(coordElementStr.charAt(16)), parseInt(coordElementStr.charAt(18)),
parseInt(coordElementStr.charAt(20)), parseInt(coordElementStr.charAt(22))]));
}
The above code works fine, but is limited to 22 chars...

I'd like it to parse the node regardless of length by first calculating the length and then looping through the push based on that int (tileWidthNumber).

Any thoughts?

It's important to ignore the commas from the node, and the push each value to the myMap array.

Thanks!

Array Name = Dynamic Variable
i have got the code:


Code:
var id = 342;
id = new Array();
id[0] = user;
id[1] = x;
id[2] = y;
what i need to happen is when I trace the value 342[0];, it needs to return user


Code:
trace(342[0]);
in a normal situtation one would do:


Code:
trace(id[0]);
to get this value, as I am setting the array so later on I can use a loop command to compare for instance this valuex with that value x;

Dynamic Array Populating
I need to load the images and then fill up the five arrays dynamically. The part of interest is how to reference the array with the string variable (arrName.. headshots_thumbs, kids_thumbs, maternity_thumb etc...)

This is the line which I wrote which is supposed to reference the arrays correctly.

MovieClip(_root[arrName]).push(_mc);








Attach Code

var myVars:LoadVars = new LoadVars();
var arrImageNames:Array = new Array();
var index:Number = 0;
var counter:Number = 100;
var folder:String;
var arrImages:MovieClip = new Array();
var headshots_thumbs:Array = new Array();
var portraits_thumbs:Array = new Array();
var maternity_thumbs:Array = new Array();
var kids_thumbs:Array = new Array();
var weddings_thumbs:Array = new Array();
var thumbsFolders:Array = new Array("headshots", "portraits", "maternity", "kids", "weddings");
// Load an array of thumbs for each folder.
function LoadNextThumbsArray() {
if (index<thumbsFolders.length) {
folder = thumbsFolders[index];
LoadMovieClipsArray();
index = index+1;
} else {
trace("starting");
Start();
}
}
function LoadMovieClipsArray() {
myVars = new LoadVars();
myVars.onLoad = OnLoad;
var path:String = "http://localhost/getimages.php?folder=portfolio/"+folder+"_thumbs";
myVars.load(path);
}
function OnLoad(success) {
var i:Number = 0;
if (success) {
for (var x in myVars) {
var arrImageName:String = myVars[x];

if (arrImageName.toLowerCase().indexOf(".jpg", 0)>0) {
trace(arrImageName);
var folderName:String = eval(folder);
var arrName:String = folder+"_thumbs";
// eval(arrName).push(arrImageName);
// Load movie onto the movieclip.
var _mc:MovieClip = _root.createEmptyMovieClip("thumb"+counter, counter);
_mc._alpha = 100;
_mc.loadMovie("portfolio/"+folder+"_thumbs/"+arrImageName);
_mc._x = counter;
_mc._y = counter;

MovieClip(_root[arrName]).push(_mc);
trace(_root[arrName][x]);
counter = counter+1;
}
}
LoadNextThumbsArray();
} else {
trace("failed");
}
}

























Edited: 05/17/2007 at 10:04:30 PM by jwize

Passing Dynamic Array
I'm designing an embedable dynamic player, and am SOOOO close! I've developed it to where my index grabs a video URL and dynamically builds a variable. Then the index uses a javascript function to make the movie player with SWFobject, and adds the variable which I can access from the root to play the video. This all works fine and dandy.

I'm adding the last piece of functionality to the player, which is playlist support. Most of my videos are concerts, so I'm trying to make it easier to watch the whole show. How can I pass an array with swfobject that I can access in the flash application?

Any direction to give me? My code is below...







Attach Code

In the INDEX, this is the dynamic variables built by PHP:

var swfTest = {firstTest:'Java Success', secondTest:'Second Variable Accepted', javaURL:'df_cm_08'};

In the JAVASCRIPT, this is the code ran for swfobject to build the player and interject the variables:

function writeMovieTest(player_div, force)
{
var so = new SWFObject("test.swf", "sotester", "480", "450", "8", "#FFFFFF");
so.addVariable("testText", "test successful");
for (var x in swfTest)
{
so.addVariable(x, swfTest[x]);
}
so.write(player_div);
}

Dynamic Buttons From Array
I'm trying to create a series of buttons from an array. The array contains the names I want on the buttons. I am able to do this by creating empty movie clips with internal textfields using the array index :

_root.level1Menu = new Array();
_root.level1Menu = ["File", "Storage", "Security", "Power", "Advanced"];

for (var i = 0; i<level1Menu.length; i++) {
_root.createEmptyMovieClip("menu"+i,i);
_root["menu"+i].createTextField("menuTitle"+i,i,0,0,0,0);
_root["menu"+i]["menuTitle"+i].text = level1Menu;

}

Once all the button objects are created - how do I assign event handlers to them without having to name them individually?

I tried assigning the behaviors to them inside of the For loop that created them but it doesn't work. It works outside of the loop when I name them individually. For example I want the text to change color when rolling over.

_root["menu"+1].onRollOver = function() {
_root["menu"+1]["menuTitle"+1].textColor = 0x0000FF;

};

Dynamic Array Naming
Here's a simple requirement...

var arrayName:String = "tabAy_"+commTrayNo;
var this[arrayName] = new Array();

..but the second line gives an error: Identifier expected. How can I generate a valid identifier for my new array?

Dynamic Array Names
Hi All

Starting the Actionscript 3 learnign curve!

I need to create a dynamic array from a loop ie

in simple terms



x is my loop counter <3

array_ {x}.push(value);


what i want here is:

array_1
array_2
array_3


Everthing else is working fine, just cant sort this out....



really cant get this to work in my class....

any ideas how i can do this?


Thanks..

Copyright © 2005-08 www.BigResource.com, All rights reserved