ukko
April 3, 2006, 2:19pm
1
I have created a simple array that attaches the mc 0 to 23 from the library randomly and used Array.splice(); to remove an element from the array once it has been displayed to the stage but it doesn’t work.
I think the problem is in my for and splice methods
but I dont know what it is, something simple Im sure.
for (i = 0 ; i <= picArray.length; i++)
picArray.splice(this.picArray[rndNum]);
can someone help me please
var picArray:Array = new Array();
picArray[0] = "bottle";
picArray[1] = "bucket";
picArray[2] = "carrierbag";
picArray[3] = "chair";
picArray[4] = "coat";
picArray[5] = "cushion";
picArray[6] = "envelope";
picArray[7] = "fork";
picArray[8] = "hat";
picArray[9] = "jug";
picArray[10] = "key";
picArray[11] = "kitchenroll";
picArray[12] = "lunchbox";
picArray[13] = "mirror";
picArray[14] = "newspaper";
picArray[15] = "pan";
picArray[16] = "phonebook";
picArray[17] = "pictureframe";
picArray[18] = "spoon";
picArray[19] = "toyboat";
picArray[20] = "toydoll";
picArray[21] = "trophy";
picArray[22] = "trouser";
picArray[23] = "vase";
for (i = 0 ; i <= picArray.length; i++)
{
rndNum = Math.floor(Math.random(23) * picArray.length);
this.blank.attachMovie(this.picArray[rndNum], pic1, 0);
trace(i + " : " + rndNum + " : " + picArray[rndNum]);
i = 0;
picArray.splice(this.picArray[rndNum]);
}
stop();
ukko:
I have created a simple array that attaches the mc 0 to 23 from the library randomly and used Array.splice(); to remove an element from the array once it has been displayed to the stage but it doesn’t work.
I think the problem is in my for and splice methods
but I dont know what it is, something simple Im sure.
for (i = 0 ; i <= picArray.length; i++)
picArray.splice(this.picArray[rndNum]);
can someone help me please
var picArray:Array = new Array();
picArray[0] = "bottle";
picArray[1] = "bucket";
picArray[2] = "carrierbag";
picArray[3] = "chair";
picArray[4] = "coat";
picArray[5] = "cushion";
picArray[6] = "envelope";
picArray[7] = "fork";
picArray[8] = "hat";
picArray[9] = "jug";
picArray[10] = "key";
picArray[11] = "kitchenroll";
picArray[12] = "lunchbox";
picArray[13] = "mirror";
picArray[14] = "newspaper";
picArray[15] = "pan";
picArray[16] = "phonebook";
picArray[17] = "pictureframe";
picArray[18] = "spoon";
picArray[19] = "toyboat";
picArray[20] = "toydoll";
picArray[21] = "trophy";
picArray[22] = "trouser";
picArray[23] = "vase";
for (i = 0 ; i <= picArray.length; i++)
{
rndNum = Math.floor(Math.random(23) * picArray.length);
this.blank.attachMovie(this.picArray[rndNum], pic1, 0);
trace(i + " : " + rndNum + " : " + picArray[rndNum]);
i = 0;
picArray.splice(this.picArray[rndNum]);
}
stop();
maybe like this?
var i =0
trace(picArray.length)
rndNum = Math.floor(Math.random()*picArray.length);
this.blank.attachMovie(picArray[rndNum], "pic"+i, i++);
picArray.splice(rndNum,1);
trace(picArray.length)
[ot]the new mod gets busy [/ot]
ukko
April 4, 2006, 9:58am
4
thanks for the help
no still not removing attached MC from array when displayed to screen.
I can’t figure out what I am doing wrong.
trace
trace(picArray.length + " : " + rndNum + " : " + picArray[rndNum]);
output to code
i.e jug and bucket have been repeated
23 : 5 : envelope
23 : 8 : jug
23 : 8 : jug
23 : 9 : key
23 : 14 : pan
23 : 20 : trophy
23 : 0 : bucket
23 : 17 : spoon
23 : 2 : chair
23 : 18 : toyboat
23 : 19 : toydoll
23 : 21 : trouser
23 : 0 : bucket
23 : 13 : newspaper
23 : 19 : toydoll
23 : 0 : bucket
23 : 17 : spoon
23 : 8 : jug
23 : 11 : lunchbox
23 : 16 : pictureframe
23 : 9 : key
23 : 15 : phonebook
23 : 2 : chair
23 : 9 : key
ukko:
thanks for the help
no still not removing attached MC from array when displayed to screen.
I can’t figure out what I am doing wrong.
trace
trace(picArray.length + " : " + rndNum + " : " + picArray[rndNum]);
output to code
i.e jug and bucket have been repeated
23 : 5 : envelope
23 : 8 : jug
23 : 8 : jug
23 : 9 : key
23 : 14 : pan
23 : 20 : trophy
23 : 0 : bucket
23 : 17 : spoon
23 : 2 : chair
23 : 18 : toyboat
23 : 19 : toydoll
23 : 21 : trouser
23 : 0 : bucket
23 : 13 : newspaper
23 : 19 : toydoll
23 : 0 : bucket
23 : 17 : spoon
23 : 8 : jug
23 : 11 : lunchbox
23 : 16 : pictureframe
23 : 9 : key
23 : 15 : phonebook
23 : 2 : chair
23 : 9 : key
copy/paste this into a new movie and see what you get in the output window
var picArray:Array = new Array();
picArray[0] = "bottle";
picArray[1] = "bucket";
picArray[2] = "carrierbag";
picArray[3] = "chair";
picArray[4] = "coat";
picArray[5] = "cushion";
picArray[6] = "envelope";
picArray[7] = "fork";
picArray[8] = "hat";
picArray[9] = "jug";
picArray[10] = "key";
picArray[11] = "kitchenroll";
picArray[12] = "lunchbox";
picArray[13] = "mirror";
picArray[14] = "newspaper";
picArray[15] = "pan";
picArray[16] = "phonebook";
picArray[17] = "pictureframe";
picArray[18] = "spoon";
picArray[19] = "toyboat";
picArray[20] = "toydoll";
picArray[21] = "trophy";
picArray[22] = "trouser";
picArray[23] = "vase";
var i = 0;
trace(picArray.length);
mi = setInterval(function () {
rndNum = Math.floor(Math.random()*picArray.length);
//this.blank.attachMovie(picArray[rndNum], "pic"+i, i++);
trace("picArray.length= "+picArray.length+" picArray[rndNum] = "+picArray[rndNum]);
picArray.splice(rndNum, 1);
if (picArray.length == 0) {
clearInterval(mi);
}
}, 1000);
made a quick file with the attachMovie stuff
ukko
April 4, 2006, 3:21pm
7
stringy:
copy/paste this into a new movie and see what you get in the output window
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#000000]var [/COLOR] picArray:[COLOR=#0000FF]Array[/COLOR] = [COLOR=#000000]new [/COLOR] [COLOR=#0000FF]Array[/COLOR]COLOR=#000000 [/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“bottle”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“bucket”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]2[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“carrierbag”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]3[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“chair”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]4[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“coat”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]5[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“cushion”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]6[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“envelope”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]7[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“fork”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]8[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“hat”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]9[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“jug”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]10[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“key”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]11[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“kitchenroll”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]12[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“lunchbox”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]13[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“mirror”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]14[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“newspaper”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]15[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“pan”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]16[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“phonebook”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]17[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“pictureframe”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]18[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“spoon”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]19[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“toyboat”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]20[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“toydoll”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]21[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“trophy”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]22[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“trouser”[/COLOR];
picArray[COLOR=#000000][[/COLOR][COLOR=#000080]23[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#FF0000]“vase”[/COLOR];
[COLOR=#000000]var [/COLOR] i = [COLOR=#000080]0[/COLOR];
[COLOR=#0000FF]trace[/COLOR]COLOR=#000000 [/COLOR];
mi = [COLOR=#0000FF]setInterval[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]function [/COLOR] COLOR=#000000 [/COLOR] [COLOR=#000000]{[/COLOR]
rndNum = [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]floor[/COLOR]COLOR=#000000 [/COLOR];
[COLOR=#808080]//this.blank.attachMovie (picArray[rndNum], “pic”+i, i++); [/COLOR]
trace[COLOR=#000000]([/COLOR][COLOR=#FF0000]"picArray.length= “[/COLOR]+picArray.[COLOR=#0000FF]length[/COLOR]+[COLOR=#FF0000]” picArray[rndNum] = "[/COLOR]+picArray[COLOR=#000000][[/COLOR]rndNum[COLOR=#000000]][/COLOR][COLOR=#000000])[/COLOR];
picArray.[COLOR=#0000FF]splice[/COLOR][COLOR=#000000]([/COLOR]rndNum, [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR];
if [COLOR=#000000]([/COLOR]picArray.[COLOR=#0000FF]length[/COLOR] == [COLOR=#000080]0[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
clearIntervalCOLOR=#000000 [/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR], [COLOR=#000080]1000[/COLOR][COLOR=#000000])[/COLOR];
[/LEFT]
[/FONT]
thanks stringy this array has been doing my head in, been going through flash mx 2004 actionscript book looking for answers…
so to attach Movie to stage all you will need is
this.blank.attachMovie(picArray[rndNum]);
ukko
April 4, 2006, 3:25pm
8
ukko:
thanks stringy this array has been doing my head in, been going through flash mx 2004 actionscript book looking for answers…
so to attach Movie to stage all you will need is
this.blank.attachMovie(picArray[rndNum]);
didn’t see attachment will have a look at that thanks again
ukko:
thanks stringy this array has been doing my head in, been going through flash mx 2004 actionscript book looking for answers…
so to attach Movie to stage all you will need is
this.blank.attachMovie(picArray[rndNum]);
blank.attachMovie(picArray[rndNum], picArray[rndNum], blank.getNextHighestDepth());
in the file i uploaded change the code to this -might be nearer to what you want
this.createEmptyMovieClip("blank", 1);
mi = setInterval(function () {
rndNum = Math.floor(Math.random()*picArray.length);
var clip = blank.attachMovie("pic", picArray[rndNum], blank.getNextHighestDepth());
clip._x = random(750);
clip._y = random(550);
clip.myText.text = picArray[rndNum];
trace("picArray.length= "+picArray.length+" picArray[rndNum] = "+picArray[rndNum]);
picArray.splice(rndNum, 1);
if (picArray.length == 0) {
clearInterval(mi);
}
}, 1000);
i was too lazy to put loads of clips in the library-there is only 1 with linkage “pic”
ukko
April 4, 2006, 3:36pm
10
stringy:
ActionScript Code:
[FONT=Courier New][LEFT]blank.[COLOR=#0000FF]attachMovie[/COLOR][COLOR=#000000]([/COLOR]picArray[COLOR=#000000][[/COLOR]rndNum[COLOR=#000000]][/COLOR], picArray[COLOR=#000000][[/COLOR]rndNum[COLOR=#000000]][/COLOR], blank.[COLOR=#0000FF]getNextHighestDepth[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR];
[/LEFT]
[/FONT]
I modified the code and testing
var clip = _root.attachMovie(picArray[rndNum] , “pic”+i, i++);
and
picArray.splice(picArray[rndNum] );