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




Array Help



Hello
Can someone help solve this for me so I can get my head around how to use arrays. Would be much appreciated?!

I have one object which changes to a different size everytime a different button is clicked. I have this on the button.


Code:
object1._xscale = 100;
object1._yscale = 100;

object2._xscale = 65;
object2._yscale = 65;
etc, etc...

Now how would I put this in an arrray so I dont have to keep writing xscale, yscale everytime? In other words I want to be able to just write the values.



KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 01-08-2007, 01:48 PM


View Complete Forum Thread with Replies

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

Array, Array HELP - Importing A External File Into N ARRAY - Almost There
I am reading and external file with the following code:

ActionScript Code:
on (release, keyPress "<Enter>") {
lv = new LoadVars();
lv.onLoad = function() {
questions1 = this.filelist0.split(",");
answers1 = this.filelist1.split(",");
for(i=0;i<questions1.length;i++)
//trace(questions1[i]+"   "+answers1[i]);
trace(questions1[i]);

//assumes same number of scores in each list
};
lv.load("questions.txt");
}


When I parse the file it puts it into an columar format as it should...however I need it to look like this:

questions1=new Array ("2+4=?","What is the capital of Illinois?","What color is the sky?","10x(5+2)=?");

answers1=new Array ("8","springfield","blue","70");


How do I do that?

Text file look like this:

&questions1=2+4=?,What is the Capital of Illinois?,What color is the sky?,10x(5+2)=?")&
&answers1=8,springfield,blue,70&

Pls Help: Need To Create New Array Taking 3 Random Entries From An Existing Array
Hello

I have a 2d array:

qTeeth[1] = [How many teeth do we have?, 1-10, 11-20, 21-30, 11-20]
etc.

It goes [question, option1, option2, option3, real answer]

I now just want to extract 3 or so of these entries and create a new array with them. Since I want to just use 3 or so questions randomly from a large array of questions.

Does anyone know a good tidy script to do this with??


Thanks in advance,
Ben.

If I Type Array[1]=array[2] Their Values Are Permanently Linked. How Do I Change This
e.g.

Code:
array[2][0] = 4;
array[1] = array[2];
array[1][0] = array[1][0] + 3;

trace("array[1]= " + array[1]);
trace("array[2]= " + array[2]);


Result:
array[1]=7;
array[2]=7;


The result I want is:
array[1]=4;
array[2]=7;




How do I achieve this?

Array Text Into Textfield And Creating New Line For Each Array Element
I have an array called dropTarg1 which stores dropped-in items.

I want to loop through this array and in a textfield, display each array item on a new line of this text field

I think I need to use something like Array.join("/n") but I can't get it working properly. I hope that the /n would create a new line of the text field called reviewBoxContentText.

for(var i:Number = 0; i<dropTarg.length; i++){
with(reviewBoxContent.reviewBoxContentText){
autoSize = true;
text = dropTarg1.join("/n");
}
}

All that is happening though is that the text field displays on a single line with /n in between each array element.

Calling A Function With An Array Variable As Arguments Is Resetting Array?
I'm going to post the full code of the two functions, disregard the "fluff" unrelated to the two functions as it is all working flawless, I've tested this HEAVILY and cannot understand why it keeps setting the entire array to undefined!

Any help would be grateful.

ActionScript Code:
// processReplace Function    function processReplace(transferFiles) {        var processArray:Array = transferFiles.slice();        var fileName:String = new String();        var filesArray:Array = new Array();        var replaceArray:Array = new Array();        var exists:String = new String();        var error:String = new String();        var promptResult:String = new String();        // Check        for (i=0; i<processArray.length; i++) {            // This is where it bugs up            <b>exists = processSearch(transferFiles[i][1]);</b>             if (exists == "replace") {                replaceArray.push(processArray[i]);            } else {                filesArray.push(processArray[i]);            }        }        // Prompt        if (replaceArray.length>0) {            error = "Replace "+replaceArray.length+" item(s):

";            for (i=0; i<replaceArray.length; i++) {                error += " - "+replaceArray[i][1]+"
";            }            promptResult = mSystem.messageBox(error, "Replace Existing Files?", 4);        }        // Action                  if (promptResult == "NO") {            transferFiles = filesArray;        } else if (promptResult == "YES") {            transferFiles = filesArray.concat(replaceArray);        }        processTransfer(transferFiles);    }

The processSearch

ActionScript Code:
// == processSearch Function    function processSearch(sentInfo) {        for (i=0; i<_global.boxFiles.length; i++) {            if (_global.boxFiles[i] == sentInfo[1]) {                return "replace";                break;            }        }    }

Basically it's supposed to check to see if the file exists and return as true if it does and add it to a replace array, then the replace array is processed into a single string and put into a dialog box through the flash wrapper prompting them to "replace the files or not".

It makes the replace array just fine, it actually even has the right "count" in it but it's setting all the "filenames" to undefined because of the exists = processSearch function.

I even tried to make a new array and run the search just from that one and set the values from the old one and it's still failing.

Is it because of the "break" or can anyone figure it out? Iknow it's hard because you can't use the code

ANY Solution ideas are welcome, even if you think it's dumb

Thanks!

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

Array.splice Works But Array.slice Doesnt?
This should be simple enough. I have an array of objects, and I want to SLICE a piece of the array and assign it to a new array. All of my attempts have failed. SPLICE works, and I could duplicate my original array into a temp array and splice out what I want, but surely slice is supposed to save me this trouble, right?

I'm a bit baffled, but here's the code:


Code:

private function createGlist() {

var glistObj:Glist = this;

xml_object = new XML();
xml_object.ignoreWhite = true;

xml_object.onLoad = function(success:Boolean):Void {
if(success) {
var i:Number = 0;
for (var this_node = this.firstChild.firstChild; this_node != null; this_node = this_node.nextSibling) {
glistObj.thumb_array.push(new Gthumb(glistObj, glistObj.thumb_array_mc.getNextHighestDepth(), this.firstChild.childNodes[i]));

i++;
}

var load_start:Number = 2;
var load_count:Number = 2;
glistObj.thumb_load_array = glistObj.thumb_array.slice(load_start,load_count);
trace(glistObj.thumb_load_array); //no result, no error
trace(glistObj.thumb_array.slice(load_start,load_count)); //no result, no error
trace(glistObj.thumb_array.splice(load_start,load_count)); //outputs [object Object],[object Object]
} else {
//error
}
}

xml_object.load(xml_url);
}

Array Copy Points To Original Array Instead Of Duplicating
Hey all.
Spent a long time trying to figure out what was wrong with my code. Then I remembered about arrays being objects instead of primitive variables. My question is, how can I make a duplicate copy of an Array?

Details:

So this code

PHP Code:




package{
    import flash.display.*
    public class tester extends MovieClip{
        var a:Array = [1,2]
        public function tester () {
            var b = a
            trace (a)
            b.splice(1,1)
            trace (a)
        }
    }
}







results in this output:

PHP Code:




1,2
1







How can i make b an actual duplicate of a, instead of a pointer?

PHP Code:




b = new Array
b = a






doesn't work either.
Thanks!
DHP

Creating Multi-dimentional Array From Single Array
I have an array

myArray=[hello,bye,fred,1,2,3,4,5,6];

I need to convert it to a multi-dimentional array that would look something like below

array1=[hello,bye,fred];
array2=[1,2,3];
array3=[4,5,6];

newArray=[array1, array2,array3];

I am not sure how to split the array can anyone help? myArray.length/3 would give me the number in each of the new arrays but I am puzzled after this?

Associating Array Elements With Another Array Keeping The Order.
hi, i have already posted this problem yesterday but i haven't solved it yet.
i have two arrays:

array_1[a,b,c,d]
array_2[01,02,03,04]

the first array represents mcs in my stage - the buttons of the menu.
the second represents other mcs, containing some text.

when i rollOver each element of array_1 i would like to show each element of array_2 in the same order and hide it when i rollOver another menu button to show a new one.

I mean, it always has to be showing a with 01, b with 02, c with 03...

any suggestions?

Array Of Movie Loaders/array Of Image Files
Alright. I'm fairly new to Actionscripting, so if we can somewhat lame out the tech talk to mild to medium I'd appreciate it. what I am trying to do is create an swf movie that will interact with a PHP script. first lets start with saying the PHP script reads the directory that it is currently in and filters out any file that is not a GIF,PNG, or JPG and then it suffes all of this into a URL encoded string and the directory path ,such as :

?pictures=image1+image2+image3+image4&path=http://servername/directoryPath

now i have flash load the variables "pictures" and split the images and stuff those into an array and the directory path of course stays in its own seperate variable. ive gotten this far with no problems.

so what im trying to do now with this info is create a bit of a slide show. I want to take the array of pictures and load those into an empty movie clip displaying each picture consecutively. Ive made several attempts but no such luck. Ive tried to use a for() loop to cycle through the array of pictures loading them into the empty clip. im still very new and rather lost with these objects and class use i. Im sure im probably not using a listener of somesort that i need and what not. I am sorry i am probably not giving enough info for all this. the whole idea of this clip is to be able to display an indefinite amount pictures , so the flash player will not know ahead of time how many pictures till the php script has sent all the names of what is in the directory. this movie needs to be able to dynamically load any images that are in that directory.so any suggestions on what i can do with an array an an empty clip? thank you to anyone who can make suggesions.

How Do I Lope Through Array, Delete Clip And Remove From Array
I have a function that creates an instance of a movieClip and adds it to an array.

In my gameloop I loop through the array and change some values. Now I want a cleanup function that loops through the array, and if the y value exceeds a certain value, I want to delete the clip instance and remove the record in the Array.

Could someone please help me with the syntax for that? I will lay the code out below.

Thankyou







Attach Code

var myClipArray = new Array();

public function createClipInstance() {
var myClipInstance:myClip = new myClip();
myClipInstance.y = 0;
addChild( myClipInstance );
myClipArray.push(myClipInstance);
}


// loop through array and check y value
// if y > 400: Delete clip and remove from array



public function cleanClips() {
for (var n:int = 0; n<myClipArray.length; n++){
if (myClipArray[n].y > 400) {

// DELETE CLIP AND REMOVE FROM ARRAY

trace("this is where I need help");
}

}
}

Generate Random Value From Array 'excluding' The Current Array Value
getting my head round flash (sorta!)...

ok, nearly got this working; i have 11 movie clips on the root timeline and a empty controller movie. what i need to happen is for a random movie clip to play. when it reaches a point in it's own timeline, it sets the playNext variable to true and the controller movie clip works out the next random movie to play.

the problem comes when the controller 'randomly' picks the movie clip thats already playing! then the whole thing breaks...

is there a way that i can say 'generate me a random clip to play from this array 'excluding' the currently playing movie clip'?

any suggestions would be grand.

this is what i have on my controller clip:

onClipEvent (load) {
//define a new array
video_array = new Array();
//list each of the videos
video_array[0] = "zero";
video_array[1] = "one";
video_array[2] = "two";
video_array[3] = "three";
video_array[4] = "four";
video_array[5] = "five";
video_array[6] = "six";
video_array[7] = "seven";
video_array[8] = "eight";
video_array[9] = "nine";
video_array[10] = "ten";
//this is the count of how many elements (videos) are in your array
max = video_array.length;
//set the playNext to true
_root.playNext = true;
}
onClipEvent (enterFrame) {
//if playNext is true
if (_root.playNext) {
//generate a new random video to play
randomNumber = Math.floor(Math.random()*max);
//store the name
randomVideo = video_array[randomNumber];
//tell that video to play
_parent[randomVideo].gotoAndPlay(13);
//record the video we are playing
crntVideo = randomVideo;
//set playNext to false
_root.playNext = false;
}
}

Load Xml Images-->Array-->Duplicate Array: AHAA
Hello Kirupians!
[Summary]
I want to load images from an XML, then store the images inside an array, then duplicate that array into other clone arrays so that I can addChild() copies of the images into stage whenever i want (and be able to change their properties).
Basicly i have to create two duplicates; big_img and icon_image

[SYMPTOMS]
Everything is loaded fine;the big_imgloads and positions correctly, but, when i try to load icon_image the first big_img disappears! as if the new array has hasn't duplicated the original array (as if it's only a shortcut, not a real copy).

The cody thing:

ActionScript Code:
// total images read from XMLvar axiLength=Accessoir.length();// main image container arrayvar axxARR:Array = new Array();// add images to arrayfor (var k=0; k<axiLength; k++) {    var axxLoader:Loader = new Loader();    axxLoader.load(new URLRequest(Accessoir.PHOTO.text()[k]));    axxARR.push(axxLoader);    axxLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, axxLoaded);}function axxLoaded(e:Event):void {    // show big image    if (axiLength==axxARR.length) {        axxShow(0);    }}function axxShow(ID_AXX:Number) {    // duplicate images array    var axxImage:Array=axxARR.concat(axxARR);    // reposition it    axxImage[ID_AXX].x = product_details_swf.axx.x+(axxImage[ID_AXX].width/2)-5.5;    // Add init image to accessoires    axxImage[ID_AXX].name="axxImage";    product_details_swf.axx.addChild(axxImage[ID_AXX]);}// here i got an event listner to a button, once rolle over is triged it // should make small copies of the whole array images and put them on stage//....function rollover_button(ID_AXX:Number) {    for (var i=0; i<axiLength; i++) {        axxCreate(i);    }    function axxCreate(ID_AXX:Number) {        var axxPic:Array=axxARR.concat();        imageResizer(axxPic[ID_AXX], 50, 50);        axxPic[ID_AXX].name="axxPic_"+ID_AXX;        axxPic[ID_AXX].x=product_details_swf.axx.getChildByName("axxBG_"+ID_AXX).x+axxPicSpacingX;        axxPic[ID_AXX].y=product_details_swf.axx.getChildByName("axxBG_"+ID_AXX).y+axxPicSpacingY;        product_details_swf.axx.addChild(axxPic[ID_AXX]);    }}


[MORE INFORMATION]
I tried array duplication using; concat and slice but not work, it doesn't creat copies of the orriginal array, but just a shortcut to it!

thanx for any tips!

Generate Random Value From Array 'excluding' The Current Array Value
getting my head round flash (sorta!)...

ok, nearly got this working; i have 11 movie clips on the root timeline and a empty controller movie. what i need to happen is for a random movie clip to play. when it reaches a point in it's own timeline, it sets the playNext variable to true and the controller movie clip works out the next random movie to play.

the problem comes when the controller 'randomly' picks the movie clip thats already playing! then the whole thing breaks...

is there a way that i can say 'generate me a random clip to play from this array 'excluding' the currently playing movie clip'?

any suggestions would be grand.

this is what i have on my controller clip:

onClipEvent (load) {
//define a new array
video_array = new Array();
//list each of the videos
video_array[0] = "zero";
video_array[1] = "one";
video_array[2] = "two";
video_array[3] = "three";
video_array[4] = "four";
video_array[5] = "five";
video_array[6] = "six";
video_array[7] = "seven";
video_array[8] = "eight";
video_array[9] = "nine";
video_array[10] = "ten";
//this is the count of how many elements (videos) are in your array
max = video_array.length;
//set the playNext to true
_root.playNext = true;
}
onClipEvent (enterFrame) {
//if playNext is true
if (_root.playNext) {
//generate a new random video to play
randomNumber = Math.floor(Math.random()*max);
//store the name
randomVideo = video_array[randomNumber];
//tell that video to play
_parent[randomVideo].gotoAndPlay(13);
//record the video we are playing
crntVideo = randomVideo;
//set playNext to false
_root.playNext = false;
}
}

Copying Loaded Array Into A Local Array
I'm loading an array through loadVariablesNum (into level 0). The script properly returns array values... I've checked by using text boxes on my stage. But, when I try to store the loaded array within a local Actionscript array for manipulation, it doesn't seem to be able to read the loaded values. It's as if the stage and the frame Actionscript were independent of each other. Can anyone help?

Thanks

Inserting An Array Into An Array To Make It Multidemensional
hi there,
Using an ASP script I've managed to get strings into flash
at the moment the strings come in like this:

array1=data1,data2,data3,data4,data5
array2=celeb1,celeb2,celeb3,celeb4,celeb5

currently I'm doing this:

webfoldercontents = new Array();
webfoldercontens = websubfolders.split(",");

which creats a 2d array. what I need is this:

multidemesionalarray = [array1[array2]]

any help v.appreciated!

Danny

Saving An Array Then Importing Saved Array?
I am creating a kids activity. At the moment I am working on the stamp tool that allws them to stamp a shape in different colours over the canvas... this is working fine, however I need to track the position and colour (and maybe more later) so that the child can save the activity and go back to it later.

So far I have managed to create an array for each propery (_x position, _y position and colour) in seperate arrays as a new stamp is attached it is given a number (1,2,3,4...) and in each array entry of that number are the position or colour properties. When I save these arrays (using FSCommand in Flash5) I think thay form a string in the text document.

When I loads the array from the text document, that looks like this:

&colourArray=255,255,255,16711680,16711680,1671168 0,16711680,16711680,16711680,16711680&XposArray=23 3,420.95,389,262,556.95,674.95,619.95,481.95,458.9 5,280&YposArray=109,167,313,211,301,158,80,105,174 ,451.95

I cannot pull out the data from the arrays (colourArray[2] traces as undefined) What I want to do is a loop based on the lenght of one the arrays that attaches the stamp MC in the correct position and colour.

Hope someone can shed light on this for me... I think I need to find a way to convert the text file data from a string to an array?!?

Cheers
Oll

Copying Array Inside Array Of Arrays
Hi,

I've got an array made up of other arrays, and I need to copy one of the arrays to a tempory array (so i can copy it)

I've tried using...

TempArray = ArrayList[0].splice();

but TempArray just shows (in debugger) as undefined, any idea's??

thanks

phil.

Tracing An Array :: Sending Array Through JS Proxy
Correct me if I'm wrong, but I thought when you traced an Array, the output was [object]. For example:
code:
var x = new Array();
x.push("one");
x.push("two");
x.push("three");
x.push("four");
trace(x);


Would output: [object Object], not the array as a comma delimited string, correct?

Having a problem where I'm passing an Array to a JS function throuh the JS proxy (flash-javascript kit) and JS picks it up as a string.

How To Duplicate Array?Array.slice() Can Not Work
I test it, and Array.slice() can not work.

var arNew:Array = new Array();
var arOld:Array = [
{checked:0},
{checked:0},
{checked:0}
];

arNew = arOld.slice();
for(var i = 0; i < arNew.length; ++ i)
{
arNew[i].checked = 1;
}

for(var i = 0; i < arOld.length; ++ i)
{
trace(arOld[i].checked);
}

It seems that "arOld" had been changed and "arNew" is not a copy of "arOld", but a reference of "arOld".

How should I copy a array?

thanks for any help

Given An Array Return An Array With Only Unique Elements
if i have an array of elements like 1,2,2,1,3,3,1,2,...

I want to return only

1,2,3

so to strip out duplicates, I thought this would be easy but its proving harder than I thought.
thanks

Filling Array - Passing Array In Function
hello

I'm trying to fill an array then pass it to a function i'm tying to do it that way
but it giving me strange results when I trace things (try it and you'll see):


Code:
////////////////// fiiling the array /////////////////
for (i=1; i<=numberof_player;i++){

pos_array = new Array(numberof_player)
pos_array [i]= i
trace("in array"+pos_array [i])
}

////////////////// pasing array in function //////////////////////



function rolldice( pos_array:Array){
trace(pos_array) /// gives 4,undefined,undefined,undefined,4
}
///////////////////////////////////////////////////////////////////
maybe i'm stupid

Thanks

T

Random Array, Array Name Selected Randomly
Random Array, Array Name selected Randomly

Here is the code:

var RDNumber2x:Array = [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36, 38,40];

var RDNumber3x:Array = [3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54 ,57,60];

var RDNumber4x:Array = [4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,7 2,76,80];

var RDNumber5x:Array = [5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85, 90,95,100];

var RDNumber6x:Array = [6,12,18,24,30,36,42,48,54,60,66,72,78,84,90,96,102 ,108,114,120];

var RDNumber7x:Array = [7,14,21,28,35,42,49,56,63,70,77,84,91,98,105,112,1 19,126,133,140];

var RDNumber8x:Array = [8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128 ,136,144,152,160];

var RDNumber9x:Array = [9,18,27,36,45,54,63,72,81,90,99,108,117,126,135,14 4,153,162,171,180];

var RDNumber10x:Array = [10,20,30,40,50,60,70,80,90,100,110,120,130,140,150 ,160,170,180,190,200];

var RArray:Array = ["RDNumber2x","RDNumber3x","RDNumber4x","RDNumber5x ","RDNumber6x","RDNumber7x","RDNumber8x","RDNumber 9x","RDNumber10x"];

var RArrayBox:String;
var RArrayBoxS = 0;


RArrayBox = RArray[Math.floor(Math.random() * RArray.length)];


RArrayBoxS = RArrayBox[Math.floor(Math.random() * RArrayBox.length)];


trace(RArrayBoxS);

Heres The error:

ReferenceError: Error #1069: Property 6 not found on String and there is no default value.
at randomarray_fla::MainTimeline/randomarray_fla::frame1()

What I am trying to atchieve is randomly selecting the array name and then randomly selecting something from that array.

So I am randomly selecting from a randomly selected array

Can anyone help with my problem?

Assigning Array Objects To Variables In An Array
how do i take an array with objects [orange, red, yellow, green, blue] and assign them to another array 5 random variables named [Slot1, Slot2, Slot3, Slot4, Slot5]

so i can get results such as

Slot1 = color*
Slot2 = color*
Slot3 = color*
Slot4 = color*
Slot5 = color*


thanks !

How To Sort An Array Based On A Value Of The Objects In The Array
hi,

i have a array containing many objects like this:

arr = [{id:6,val:"bla"},{id:3,val:"bleah"},{id:10,val:"bl o"}]

now i want to sort this array based on the id values of the objects.

any ideas ?

thanks

Sorting A New Array From An Existing Array (emergency)
Hi

i got an existing array, main[y], which after an equation, will come out with another array.


Code:
if (main[y] === topicList.getValue()){
subTopic = [];
subTopic = fTitle[y]
trace(subTopic)
}
However, i could not sort the subTopic, as it gkeep giving me undefined. Is there any way to sort this subTopic, such that they are in alphabetical orders?

Appreciate any help.

Referencing Array Items With An Id Pulled From The Array
I have been modifying one of the Kirupa tutorials about loading external xml data and arrays. I have it successfully working, but i would like to figure out how to take it one step further. I want to be able to designate a each item in the arrays with an id rather than an iterative variable number and cannot figure out how to do it.

This is a snippet from the xml file:

<projects>
<item>
<id>13</id>
<projectname>First Project</projectname>
<location>Anytown, USA</location>
<units>60</units>
</item>
<item>
<id>33</id>
<projectname>Second Project</projectname>
<location>Sometown, USA</location>
<units>132</units>
</item>
</projects>

I am currently populating an array this way:

total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
id[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
projectname[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
plocation[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
units[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
}

but that just gives me references to: projectname1, projectname2 etc.
I would like to figure out how to get the <id> value from the loaded xml file connected to the variable name of each item in the array so that i can refer to the variables this way: projectname13, projectname33, etc.

Does this make sense? Can anyone help?

Setting Array Values To Variables In Another Array
I have some variables created on the main timeline and a mc called options which will be where those variables can be manipulated.

A way I've tried to this is by creating a first array(array1) and populating it will all the variable names found on the main timeline, and another array(array2) containing the values of the variables the user has changed(which are displayed on some dynamic text fields). To make these changes, an "apply" button is pressed which will set the values found in array2 to the variables in array1.

So...

Code:

PHP Code:



//variables on the main or root timelinevar1 = 1; var2 = 2; //... //within options mc timelinearray1 = [var1, var2]; array2 = [var1Display, var2Display]; apply.onRelease = function() { //set values in array2 to variables in array1 and update the main timeline's variables//... } 




How would you do this so that var1, var2... are updated properly according to the values found in array2?

And because array2 contains strings(read from dynamic textfields), how do you deal with that since var1 and var2 are numbers?

hope this all makes sense to everyone

PHP Array -> Flash Array In Function
I'm retrieving an array from PHP, bringing it into Flash, converting it to a Flash array, then passing the array values to functions in order to control playback of multiple timelines.

The PHP array consists of time values in milliseconds, and mouth positions for a character's lip-synch. For example, &time1=0.015962&mouth1=eat&time2=etc...

I want my first function to extract the first array value for time and the first array value for mouth position, and pass it to another function that reads the time, does a calculation to determine how long to pause before executing the original function again, thus leaving the mouth position passed to it and moving along to the next array value.

My problem is this: how can I write the array references into the function so that it knows each time which successive array value to extract? Do I need to pass a total number of array values initially, then trade a "current value" between the two functions (time and mouth position) to make sure the array value being retrieved is correct?

Any help is appreciated,

Mike

Simple? Array To Array Problem
I am trying to pass the value from one array element to an element in another array. I believe the value is getting there, but it won't display when the 2nd array element is used as the variable in a dynamic text block. Here's the simplistic code I'm trying to learn the concept with:

one = new Array(5);
one[0]=1;
one[1]=2;
one[2]=3;
one[3]=4;
one[4]=5;
two = new Array(5);
two[0]=one[4];
two[1]=one[3];
two[2]=one[2];
two[3]=one[1];
two[4]=one[0];

I then set up individual dynamic text boxes for two[0] through two[4], but no value will show.

Link Array 2 To Randomized Array 1
Hi,

I am trying to do the following:

I have a textfile that contains 2 variable sets:

&songs=bluestravelertest.swf|aridtest.swf|dmbtest. swf|joewalshtest.swf&eof=1
&info=<br><b>Blues Traveler</b><br>Onslaught|<br><b>Arid</b><br>Little Things of Venom|<br><b>Dave Matthews Band</b><br>Mother, Father|<br><b>Joe Walsh</b><br>Funk #49&eof=2

The 'songs' var I use to load a new swf in an empty MC, the 'info' var I use to load into a dynamic textfield. Both vars are properly parsed via a function (no problems here).


I created a button that should shuffle the 'songs' var.


Code:
var o=_root.myArray.slice(myArray[0], myArray(total))
var newlength=o.length
var shuffledArray=new Array()
for(var i=0;i<newlength;++i){
var r=random(o.length)
shuffledArray[shuffledArray.length]=o[r]
//o[r]=o[o.length-1]
o[r]=o[o.length-1]
o.pop()
}


This all works fine, but how can I link the 'info' var to the 'songs' var after it has been shuffled? (in other words, how can I get the 'info' var 2 to load when 'songs' var 2 is loaded)?


It's kinda late, so let me know if it is not clear.

I really hope you can help me here, because I have been working on this for ages, but I simply can't get it to work.


Thx in advance.


With kind regards,

RF

Question: PHP Array To Flash Array?
I've searched many topics about this and they have helped me a little bit, but I can't quite get my PHP array to go into Flash as an array. I think the method I want to do is echo my PHP array as a string separated by commas and then bring that into flash and split it.

1. I'm not quite sure how I could format my PHP array as a string separated by commas.

2. I'm not sure how to bring it into Flash via LoadVars.

Heres what I have so far:


PHP Code:



<? // test.php
include('db.php');
dbConnect("slayer");
$result=mysql_query("select*from portfolio");
$num=mysql_num_rows($result);
echo "&num_results=" . $num;
$myArray=$row["name"];
for($i=0;$i<=$num;$i++){
$row=mysql_fetch_array($result, MYSQL_BOTH);
echo "&name$i=" . $myArray[$i];
}
?>





code: on (release) {
myData = new loadVars();
myData.load("test.php");
myData.onLoad = function(success) {
if (success) {
var i = 0;
while (this["myArray" + i] != undefined) {
_root.myVar = this["myArray" + i];
i++;
}
}
};
}


Thanks for any help or tips. I would really appreciate it greatly.

ARRAY Element Value - Not Array Index Value
Hi all -
Have a small problem converting the below variables from PHP into a useful Ascript Array. I keep getting the value of the array index, rather than the value of the variable in question.


So I know I have 3 rows in my database (totalRows var),
and I have a incremental values for the "recordId"'s (which correspond to the record ID in the db).

totalRows = 3

recordId0 = 1
recordId1 = 5
recordId2 = 6

this is the code I am using:

Code:
function extractMenu() {
//returned vars (FYI): totalRows=3&recordId2=6&recordId1=5&recordId0=1&result=okay&
this.menuArray = new Array();
with (menuLoad) { //menuLoad is the LoadVars object holding PHP vars.
for (i=0; i<=totalRows-1; i++) {
menuArray[i] = recordId + i;
trace(menuArray[i]);
//the trace returns:
//0
//1
//2
//I was expecting the values:
//1
//5
//6
}
}


any takers?

Array Data Is Set Then Lost... But Just One Array
Hi,

I have 3 arrays, 2 hold different information which will be combined into the third one.

The creation/population of each array is done with in each own function as results are sent back to the flash from remoting.

I have attached a mock up of the code below.


Code:

array1 = new Array();
array2 = new Array();
array3 = new Array();

combineArrays = function () {
for (j=0; j< array2.length; j++) {
array3.push({something:array1[j].something, something:array2[j].something, ....});
}
this.myGrid.setDataProvider(array3);
};

query2_Result = function (result) {
array2.push({something:result[0].something, ....});
};

query1_Result = function (result) {
aMatrix = result;
for (i=0; i<aMatrix.length; i++) {
array1.push({something:aMatrix[i].something, ....});
remoting.query2(int(aMatrix[i].something), "");
}
combineArrays();
};
array1 and array3 keep the data that was populated into it. But by the time we reach the combine function array2 has no data.

I'm not sure why its losing the information, if you trace with in query2_Result() you get all the information that was populated into the array2.

Any help would be greatly appreciated.

Ty,
alex

Reading Array, Not Setting Array
Sorry everyone, I think I'm making a simple mistake but I just can't see it.


I'm using an array to store the order of something, I also make a backup of that array as a reference to remember what that first array looked like.

The problem comes when I'm using the values of that backed up array to populate the first array. What happens is that the backed up array gets it values overwritten, when all I wanted to do was read its values, not set its values.

Heres what I'm up to :



Code:
// Sets initial array
var ButtonOrder = new Array("One", "Two", "Three", "Four");

// Makes a backup of the initial array
ButtonOrderBackup = ButtonOrder;

// Changes the initial array with values from the backup
// (This is where I think the problems at)
ButtonOrder[0] = ButtonOrderBackup[3];
ButtonOrder[1] = ButtonOrderBackup[2];
ButtonOrder[2] = ButtonOrderBackup[1];
ButtonOrder[3] = ButtonOrderBackup[0];


// Trace Backup array
for (i = 0; i < ButtonOrderBackup.length; i++)
{
trace("Backup " + i + " " + ButtonOrderBackup[i]);
}
trace("");


// Trace initial array
for (i = 0; i < ButtonOrder.length; i++)
{
trace(i + " " + ButtonOrder[i]);
}
trace("");
Heres what the debugger feeds back to me :


Code:
Backup 0 Four
Backup 1 Three
Backup 2 Three
Backup 3 Four

0 Four
1 Three
2 Three
3 Four
I was wanting the initial array to have the values: Four, Three, Two, One. And the backup array to be how it was originally : One, Two, Three, Four.

What have I done wrong, thank you.

Populate An Array Values From An Array
ok i have this xml file

Code:
<artworkinfo>
<movieinfo>
<artLocation>cover1.jpg</artLocation>
<movie>Live Free or Die Hard</movie>
<plot>John McClane takes on </plot>
</movieinfo>

<movieinfo>
<artLocation>cover2.jpg</artLocation>
<movie>Meet the Robinsons</movie>
<plot>Lewis is a brilliant inventor </plot>
</movieinfo>

</artworkinfo>
the xml will tell where the cover art is the movie title and plot.
i want to populate my movie with this info what is the best approach to create empty movieclips using actionscript or create individuals MC , i try the second one and create 4 movieclips (cause the xml have 4 elements just post 2) and make an array of mc but i can find how to match the xml array to the mc array , this is the code for better explaining,


Code:
function loadXML(loaded) {

if (loaded) {

xmlNode = this.firstChild;
image = [];
movie = [];
plot = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {

image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
movie[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
plot[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;

}
placeholder=new Array(loader1,loader2,loader3,loader4);
placeholder_total = placeholder.length;
for (e=0; e<placeholder_total; e++){
placeholder[e].contentPath=this.image[i];
}


} else {

content = "file not loaded!";

}

}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("movieinfo.xml");
the stage have 4 movieclips name loader1,loader2,ect... each mc have 2 dynamic text field one for title and one for the plot.

Flash Array Works, Not Php Array
Hi!

Cant figure out what the problem is. Im using amfphp remoting to load some data from mySQL db. The weird thing is that if I "hardcode" values in an Array in Flash I get it all to work, but when I'm using the array from php it wont load the pictures. But if I trace out my array from the php-file in Flash I get the correct values...

Here's my AS:

Code:
import mx.remoting.*;
import mx.rpc.*;
import mx.remoting.debug.NetDebug;

var gatewayUrl:String = "http://localhost/flashservices/gateway.php"

NetDebug.initialize();
var _service:Service = new Service(gatewayUrl, null, 'Bilder', null , null);
var pc:PendingCall = _service.getEverything();
pc.responder = new RelayResponder(this, "handleResult", "handleError");

//Stage.scaleMode = "noScale";
function handleResult(re:ResultEvent)
//init();
//function init()
{

info_mc._visible = false;
var arrPictures = new Array();
arrPictures = re.result;

//This one works --> arrPictures = new Array("http://localhost/flashservices/services/pics/thumb_fall 017.jpg", "http://localhost/flashservices/services/pics/thumb_fall 018.jpg", "http://localhost/flashservices/services/pics/thumb_fall 019.jpg");
var xPos:Number = 90;
var nPic:Number = 0;

for (var i:Number = 0; i < arrPictures.length; i++) {
this.attachMovie("pic_holder", "pic_holder"+i, this.getNextHighestDepth(), {_x: xPos, _y: 150});
_root["pic_holder"+i].attachMovie("preloader_mc", "preloader_mc"+ i, 1);

_root["pic_holder"+i].material = arrPictures[i]["material"];
_root["pic_holder"+i].preloader = _root["pic_holder"+i]["preloader_mc"+i].preloader_txt;


this["pic_holder"+i].onRollOver = function():Void {
_root.infoClothing();
info_mc._visible = true;
info_mc.material_txt.text = this.material;
}
this["pic_holder"+i].onRollOut = function():Void {
info_mc._visible = false;
}
xPos += 90;
}

}

//Ladda in bilderna
var index:Number = 0;

var mcLoader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {
nperc = Math.round((bytesLoaded/bytesTotal)*100);
_root["pic_holder"+index]["preloader_mc"+index].preloader_txt.text = nperc + "%";
}

listener.onLoadInit = function(target:MovieClip) {
index++;
if(index < arrPictures.length)
mcLoader.loadClip(arrPictures[index]["url"], _root["pic_holder"+index].lilla_mc);
}
mcLoader.addListener(listener);
mcLoader.loadClip(arrPictures[index]["url"], _root["pic_holder"+index].lilla_mc);
// Slut på preloader



function handleError(fe:FaultEvent)
{
trace('There has been an error');
}

function infoClothing():Void {
this.info_mc.swapDepths(getNextHighestDepth());
this.info_mc.onMouseMove = function() {
this.updateAfterEvent();
info_mc._x = _root._xmouse + 22;
info_mc._y = _root._ymouse - 10;
}
}

Mp3 Array - Won't Play Whole Array And Then Stop - Somebody Help?
I've got an array of mp3s. I'm trying to find the right combination of code to get the play button to play each mp3 in the array, then stop at the end of the array. Must keep the items in the array - so no shifting. I've come up with dozens of ways to loop the items in the array - or the other side of the spectrum - to get the play button to only play one item at a time each time you click it. This has gone on too long... Somebody has to know how to help me...

In frame 1 I've got:

ActionScript Code:
_global.DIALPAD = []
now = 0;
_global.PADSOUND = new Sound();

//then on the play button I have:

on (press) {
_global.PADSOUND.loadSound(_global.DIALPAD[(++now)%_global.DIALPAD.length]);
_global.PADSOUND.start();
}Don't ask me how I came up with the button code - I don't even know anymore. At any rate, I've got other buttons that push mp3s into the array with this code:

_global.DIALPAD.push("SOUND1.mp3");

I'm trying to get the array to play all the way through and stop there. I've tried dozens of combinations of [i] and looping - all kinds of crazy nonsense trying to piece together what I could from posts and scanning other people's code, but I'm new to AS.

I will appreciate any help you can give me. Thanks!!

A Multi-array? (or Double Array)
Is it possible to have in Actionscript a somehow multi-array like this?
(Or a double-array)

eg.:

category[0].product[0].title
category[0].product[0].size
category[0].product[0].stock
category[0].product[0].price

How can I make it work?
And retrieve values like
category[1]="this"
category[1].product[2].title = "that"

Thanks in advance!

Test If Array's Element Is An Array.
I'm recursively looking through an Array, and I'm looking for a solid way to test if an element is actually an Array(there is a chance that the tested array element is another datatype). I was thinking that I could use the length property to test, however looking in the index of ASDG2 I see that there are a few other Objects that possess the a length property, and I am afraid that this might cause a problem.

look at
nav_array[i].length >= 1
below


Is there a way to use typeof on an Array, and have it return anything other than Object?


Code:
private function recurseThroughArray(nav_array, itemsArray, depthHolder){
for(var i=0;i<nav_array.length;i++){
depthHolder.push(i);
if(nav_array[i] == itemsArray){
var returnDepth:Array = depthHolder;
break;
}else{
if(nav_array[i].length >= 1){ //make sure that this is an Array
recurseThroughArray(nav_array[i], itemsArray, depthHolder);
}else{
depthHolder.splice(depthHolder.length-1,1);
}
}
}
return returnDepth;
}
also, I'm new to recursion, and I haven't tested this yet.

How Can I Get An Array Value Using Variables When I Call The Array?
Hi! I don't know if the title is correct, but I hope i can explain this correctly so someone can help me.

I have 4 arrays: surfaceX, surfaceY, pumpX, pumpY
with the informacion in each of those arrays i'm drawing graphs in different movieclips, but in order to make things tidier i wanted to make a single function to be called that would make the graphs depending on the function info.

So.. the idea would be that with the function drawCard('graph', 'surface') it would draw the surface graphic into the graph movieclip, and with drawCard('graph2', 'pump') it would draw the pump graphic into the graph2 movieclip. Here is the code i have so far for the function:


ActionScript Code:
drawCard = function (canvas, cardType) {
    newval = _root.colorPicker.color;
    _root[canvas].clear();
    _root[canvas].lineStyle(2, newval, 100, true, "none", "round", "round", 1);
    _root[canvas].moveTo(surfaceX[0], surfaceY[0]);
    for (i=0; i<surfaceX.length; i++) {
        _root[canvas].lineTo(surfaceX[i], surfaceY[i]);
    }
};

As you may guess, the [canvas] part is working. But i don't know how to write "surfaceX[i], surfaceY[i]" to get surface replaced by cardType

i was tempted to use [cardType+'X'][i] or something like that, but it didn't work. Can anyone help me?? cheers!

Comparing Between An Array And A Multidimensional Array
Hi all, this is my first post.
I have only been working with flash for a couple of years, but I know my way around it pretty well. I usually can find answers to any problems I have through searching, but I seem to be stuck on this one....

I am trying to compare an element in an array to an element in an multidimensional array. Here is my code

var songArray:Array = new Array([["q"],["l8"],["l6"]],[["r"]],[["q"],["s5"]]);
var lineArray:Array = new Array("l8","s8","l9","s9");

var tempLine = lineArray[0];
var tempNote = songArray[0][1];

trace(tempLine) // l8
trace(tempNote) // l8

if(tempLine == tempNote) {
trace("True");
} else {
trace("False");
} // False

Why is this?
I appriciate anyones input

Thanks
builder

How To Convert Array Result Into Array.
Greetings to all...

I'm creating array of an array.. it maybe sounds confusing..To explain further, i have 3 set of array and im looping it in for loop to get the indexes. After i get the three array of indexes i want to pair them by index by putting in array again and referencing it by index to get all the value one time of the three array index.

here is the code..

var sTime:Array = new Array(515.4, 7427.47, 545.74);
var sColor:Array = new Array ("Red", "Green", "Blue");
var sNumber:Array = new Array(1, 2, 3);
var aContainer:Array = new Array();
var aData:String = new String()


for(i:Number = 0; i < sTime.length || i < sColor.length ||
i < sNumber.length; i++){
sSet = sNumber[i];
sLapse = sTime[i];
sColorName = sColor[i];

aData = sSet + " " + sLapse + " " + sColorName;
trace(aData);
}

//output:
1 515.4 Red
2 7427.47 Green
3 545.74 Blue

Now how can i put this array result to array again.. So that if i trace the value index of sumArray[0] the output will be and so on..

output: 1 515.4 Red

Thanks...

Help - Getting Array Index 0 With MultiDim Array
Howdy,
I've attached a file for some help here. I'm creating a menu structure in flash and need to pull certain names out of multiple arrays. I had this working before the arrays became multidim. Now that the arrays have become multidim the chapter heading names are all whacked. The chapter subpages are fine though.. When the file is previewed it's pulling a 0 index for one chapter header, but after that it's pulling the supbage indexes. Basically the headers of the menu need to be the [0] of the arrays.

Any help or suggestions would be helpful

thx

B

Help - Getting Array Index 0 With MultiDim Array
Howdy,
I've attached a file for some help here. I'm creating a menu structure in flash and need to pull certain names out of multiple arrays. I had this working before the arrays became multidim. Now that the arrays have become multidim the chapter heading names are all whacked. The chapter subpages are fine though.. When the file is previewed it's pulling a 0 index for one chapter header, but after that it's pulling the supbage indexes. Basically the headers of the menu need to be the [0] of the arrays.

It's under the note // populate chapter headers with text //

Any help or suggestions would be helpful

thx

B

Global Array So That Array Is Not Empty
Hi ,
I am pretty new at actionscript and flash in general. I have a question regarding global array.

I am not sure how the global variables function but my test to create an array fails. Any idea how to edit so that the "arr" is not empty. The xml file is after the code

_global.arr = new Array();
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("xml.xml");
trace(_global.arr);

function loadXML(loaded) {

if (loaded) {
var person:Array = xmlData.firstChild.childNodes;
for (var i:Number = 0; i < person.length; i++) {
var node:XMLNode = person;
//arr.push(node.childNodes[2].firstChild.nodeValue);
_global.arr = node.childNodes[2].firstChild.nodeValue;
}
} else {
trace("file not loaded!");
}
}
The xml file is here:
<?xml version="1.0"?>

<inventors>
<person>
<name>Thomas Edison</name>
<comment>Inventor of many things such as the incandescent lightbulb.</comment>
<picture>picture2.jpg</picture>
</person>
<person>
<name>Doug Engelbart</name>
<comment>Invented the mouse at the Stanford Research Institute</comment>
<picture>picture3.jpg</picture>
</person>
</inventors>

Can't Duplicate Movieclips As An Array Within An Array
Hello.
I have an animation that loads an xml into it and traces back an array within an array. I have tried to apply this to duplicated movieclips thereby creating a structured set of links. What I am trying to do is this:

Chicken Nuggets
__Compression
__Texture
__Disgust
Mega Warhead
__Taste
__Hardness
__Pain

This traces fine but I can't seem to get the duplicated movieclips to assemble in this fashion.
The code for the XML is as follows:

var controlArray:Array;
var variable:Array;
var testTopic = new Array ();
var test = new Array ();

var controlsXML:XML = new XML();
controlsXML.ignoreWhite = true;

controlsXML.onLoad = function(success:Boolean){
if (success){
var mainnode:XMLNode = controlsXML.firstChild;
var controlNodes:Array = controlsXML.firstChild.firstChild.firstChild.firstChild.childNodes;

var list:Array = new Array();
for (var i:Number = 0; i < controlNodes.length; i++) {
var personnode:XMLNode = controlNodes.attributes.Name;
trace(personnode);
testTopic.push (new struct (personnode));
var specificNode:Array = controlNodes.childNodes;
for (var j:Number = 0; j < specificNode.length; j++){
var itemnode:XMLNode = specificNode[j].attributes.Variable;
trace(itemnode);
test.push (new struct2 (itemnode));
}


}
printer ();
printer2 ();
} else {
trace('error reading XML');
}
};
controlsXML.load ("controls3.xml");

The code for the movieclip duplication is as follows:

x = 50;

function printer ()
{
for (m = 0; m < testTopic.length; m++)
{
duplicateMovieClip ( slotTopic, "slotTopic" + m, m );
slotTopic = eval ( "slotTopic" + m );
slotTopic._y += x;
slotTopic.slotTopicContent.text = testTopic[m].personnode;
}
}

function printer2 ()
{
for (k = 0; k < test.length; k++)
{
duplicateMovieClip ( slot, "slot" + k, k );
slot = eval ( "slot" + k );
slot._y += x;
slot.slotContent.text = test[k].itemnode;
}
}

function struct (personnode)
{
this.personnode = personnode;
}

function struct2 (itemnode)
{
this.itemnode = itemnode;
}

On the stage are two movieclips, titled "slotTopic" and "slot". Within those are dynamic text boxes titled respectively "slotTopicContent" and "slotContent". When I preview this file it only displays the text within the "slot" movieclip and it lists all six of the subtopics with no break. So, there are two dilemmas:

1) The movieclips won't duplicate into the structured set of links that I want.
2) "slotTopic" is not displaying text at all.

If anyone has any advice, I'd really appreciate it. Thx!

Flat Array Vs Multidimensional Array
For a game I'm making I've tried to stick with using flat arrays as much as possible because I read somewhere that its faster than using multidimensional arrays. I just need to know if anyone knows or can point me to any place which discusses the speed difference (if there is any).

Using multidimensional arrays would make my coding much easier but if its slower than flat arrays I'm willing to persevere for the better execution time.

Any thoughts?

Send Array / Receive Array
I'm unfamiliar with PHP however I know the concepts behind it. I know nothing about XML except that it is used to store and get data. On a friend's host he has PHP enabled and has set up a MySQL database for me.

My question is direct, but one of those pain in the *** "I know nothing show me exactly how to do this" type ones. How would one store an array of strings (with a size that is determined during runtime in the swf) from Flash (AS3) and then be able to get that array again during a later time, or another run of the swf?

If you need more information just say.

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