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




Sending An Array From Php



i need to know how to send an array from php to my flash movie, so that I can still access it as an ARRAY..
I know I have to use loadVariables in my movieclip, and link to the php page that will use "print" statements to display the values, but what php coding do I use?
Is it just:

Code:
<?
print "myArray="$myArray
Or do I have to use some sort of for loop to send ALL the individual portions of the array?

Also, is it possible to send an array of arrays? Does flash support that?
Thanks
irf2k



FlashKit > Flash Help > Flash ActionScript
Posted on: 03-14-2006, 06:55 AM


View Complete Forum Thread with Replies

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

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.

Sending An Array From JS To AS
I'm using the Flash Javascript methods to send data from JS variables to Flash variables.


Code:
content.SetVariable("/:lscore", existingScore);
It's working dandy except:

One of the JS variables is an Array, and I'd like it to be sent to another Array inside Flash.

Can this be done? Or do I have to send it as a string and THEN split it into an Array? I'd rather NOT do it that way because I need access to it immediately in my movie.

Sending An Array To DB
I have an array that when the user answers quiz questions, their responses to the question get added to the array. I need to get this array to a coldfusion script. From there, the CF script will add it into a database. Here are my questions:

1.Can I use the loadVars.send to send the array variable to the script?

2. How can I send the array so that each answer gets put into a seperate column in the database and not all in one? Is that something that gets taken care of in the CF script or does that get done in flash when Im ready to send off the array?

Thanks

Sending An Array From Flash To Php
Hi all, I have a question on sending an array from flash to php. I have created an associative array like this:

cart_array.push( {prod_id: _root.showing, prod_name: _root.add_name, prod_colour: _root.add_colour_name, prod_size: _root.add_size, prod_price: _root.add_price } );
// trace(cart_array[0].prod_id);
// trace(cart_array[0].prod_name);

I would like to use a loadVar method to send the cart_array to php:

myLVObj.cart_array = cart_array;
myLVObj.sendAndLoad("app_save.php", myTargetLVObj, "POST");

Am I correct? And how can I receive the associative array in PHP?

Thanks.

Sending Array Through Import.
Ok, I'm doing a little area which import obstacles from an array like this.



Code:
package
{
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;

public class Obstacle extends Sprite
{
var obstURL:String = "Obstacle.jpg"
var obstURLReq:URLRequest = new URLRequest(obstURL);
var obstArray:Array = new Array();
var containerArray:Array = new Array();
public function Obstacle()
{

for(var j:int = 0; j < 26; j++)
{
obstArray[j] = new Loader();
obstArray[j].load(obstURLReq);
}

for(var i:int = 0; i < 26; i++)
{
containerArray[i] = new Sprite();
addChild(containerArray[i]);
containerArray[i].addChild(obstArray[i]);
containerArray[i].x = 15 + 40 * i;
}
}
}
}
This create some obstacles in a line, this I then import in a different Actionscript File which look something like this.


Code:
package
{
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.KeyboardEvent;
import Obstacle;
import Runner;

public class mainStage extends Sprite
{
var ru:Runner = new Runner();
var ob:Obstacle = new Obstacle();

public function mainStage()
{
addChild(ob);
addChild(ru);
stage.focus = this;
addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
}


private function reportKeyDown(event:KeyboardEvent):void
{
if(event.keyCode == 40){
ru.y +=5;
while(ru.hitTestObject(ob.containerArray[1])){
ru.y -=1;
}
}
}
}
}
Well, this is the short version of this which shows where I have the problem.
while(ru.hitTestObject(ob.containerArray[1])){
This works fine, but my question is how I can do this when I want it to do the same hitTest on all the containers. It doesn't seem to work to import "i" when I import the rest from the Obstacle packages, or does it?
Or will I have to do another for-loop in the mainStage package as well? Maybe name the array obstacles.

Any ideas?

Sending Array From Flash To Php
Hi there,

Is there any method to send an array in Flash to php?

I try as follow:


var sendData = new LoadVars();
var r = new LoadVars();

sendData.arrayA = arrayB; //arrayB is an array in flash

sendData.sendAndLoad("saveArray.php", r, "POST");

But it seems that array in flash can NOT be sent to php in this way.

I searched previous articles, and found that one
http://www.actionscript.org/forums/s...threadid=36368

But I wonder if there is an another way to do the sending.

Thanks in advanced.

Vic

[flash8] Sending Array's To Php Via Flash Remoting And Amfphp
hi, i want to try and send an array from flash to php, using flash remoting and amfphp. how do i go about this, cus so far, i've had no luck. Has anyone got an example of how this would work, with the right syntax too maybe?

Combobox Problem Showing Full Stops After Sending Variable To Function Array
hi all.... i really need some help here, its driving me mad and i dont think i will ever solve this.

ok here goes.
im trying to populate a combobox with an array and when i send a variable to this function instead of populating the combobox with my array it instead just populates its with full stops, now when i check the output with trace it shows its ok. so this is where i so fed up. if it shows to output the correct result then why does it mess up.

here is the code for the first frame on the stage.

carArray = new Array("Chrysler","Porche","Mazda","Toyota");
foodArray = new Array("Hamburger","Hotdog","Pizza");
drinkArray = new Array("Water","Beer","Wine","Martini");

setSubCombo()

poo = drinkArray ;

function setSubCombo() {
sub_cb.removeAll();
var subArray = 'poo';
trace(poo);
for(var i=0; i<subArray.length; i++) {
sub_cb.addItem(subArray[i],subArray[i]);
}
}

and in the button i have this

on (release) {
_root.poo = 'foodArray';
_root.setSubCombo();

}

ok now i have tried this in many different ways, using global variable ect ect and no matter how many methods i use i get the same result.

so please help me for i dont have the brains to work this out.
i so hate myself right now, never ever ask for help, but this time i dont have faith in my stupid self.

love to you all.. but NO love to bush or blair

Sending Variables To PHP, Checking, And Then Sending Back
ok heres the deal:

Im making this email form in flash 2004, and I can get it to send emails and all and great so now im going back and making it error check... so basically it sends out my variables to the PHP file, checks to see if the email is from a real domain among other things, and then depending on what it sends back it will do a certain action... I can get it to send my variables but not sure how to load the variables back in to flash after the calculations are done...this is like my first flash that uses all this so im quite a n00b at it.. thanks

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.

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.

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