View Full Version : For loop tracing out weird info..
elaniobro
05-06-2008, 02:45 PM
Hey, I have this for loop that spits out info with no pattern what so ever. I can't figure it out. Any help Please?var $me:Number = new Number();
var maxLength:Number = 5;
var i:Number = new Number();
for (i = 0; i<maxLength; i++) {
trace(mcScreenShots["mcScreen"+i]);
/*mcScreenShots["mcScreen"+i]["mcScreen"+i+"a"].$me = i;
mcScreenShots["mcScreen" + i]["mcScreen" + i + "a"].addEventListener(MouseEvent.MOUSE_OVER, onScreenShotsOver);
mcScreenShots["mcScreen" + i]["mcScreen" + i + "a"].addEventListener(MouseEvent.MOUSE_OUT, onScreenShotsOut);
mcScreenShots["mcScreen" + i]["mcScreen" + i + "a"].addEventListener(MouseEvent.MOUSE_DOWN, onScreenShotsDown);*/
}
this is what the trace out puts:[object mcScreen0_2]
[object mcScreen1_6]
[object mcScreen2_9]
[object mcScreen3_12]
[object mcScreen4_15]
When it is un commented this is what outputs:[object mcScreen0_2]
[object mcScreen1_6]
TypeError: Error #1010: A term is undefined and has no properties.
at mcla_video_v01_fla::MainTimeline/frame1()
I am befuddled. Many thanks to all the help I get!
:confused::confused::confused::confused:
Slowburn
05-06-2008, 02:58 PM
$me is not a valid property of a MovieClip/Sprite/DisplayObject, your custom object must support this property.
the objects the loop is spitting out are the class objects that are within mcScreenShots.
"mcScreen2_9" is a object symbol in your library with the class mcScreen2_9 attached to it.
note: a for loop iteration variable should be cast to 'int' as it's quicker and you don't need to iterate decimals, only whole numbers.
elaniobro
05-06-2008, 04:22 PM
$me is not a valid property of a MovieClip/Sprite/DisplayObject, your custom object must support this property.
the objects the loop is spitting out are the class objects that are within mcScreenShots.
"mcScreen2_9" is a object symbol in your library with the class mcScreen2_9 attached to it.
note: a for loop iteration variable should be cast to 'int' as it's quicker and you don't need to iterate decimals, only whole numbers.
Thanks for the reply. I tried changing the var $me to a and am not geting the desired results.var a:Number = new Number(); var maxLength:Number = 5; var i:Number = new Number(); for (i = 0; i<maxLength; i++) { trace(mcScreenShots["mcScreen"+i]); /*mcScreenShots["mcScreen"+i]["mcScreen"+i+"a"].a = i; mcScreenShots["mcScreen" + i]["mcScreen" + i + "a"].addEventListener(MouseEvent.MOUSE_OVER, onScreenShotsOver); mcScreenShots["mcScreen" + i]["mcScreen" + i + "a"].addEventListener(MouseEvent.MOUSE_OUT, onScreenShotsOut); mcScreenShots["mcScreen" + i]["mcScreen" + i + "a"].addEventListener(MouseEvent.MOUSE_DOWN, onScreenShotsDown);*/ }
a= mcScreenShots.mcScreen0.mcScreen0a
I now get this error:[object mcScreen0_2]
[object mcScreen1_6]
TypeError: Error #1010: A term is undefined and has no properties.
at mcla_video_v01_fla::MainTimeline/frame1()
In addition to what you had said, "mcScreen2_9" being an object in my library, this is not so. I only have mcScreen2, mcScreen2a & mcScreen2b in my library. Thanks again for your reply.
elaniobro
05-08-2008, 11:02 PM
$me is not a valid property of a MovieClip/Sprite/DisplayObject, your custom object must support this property.
the objects the loop is spitting out are the class objects that are within mcScreenShots.
"mcScreen2_9" is a object symbol in your library with the class mcScreen2_9 attached to it.
note: a for loop iteration variable should be cast to 'int' as it's quicker and you don't need to iterate decimals, only whole numbers.
I've modified the code to this:var maxLength:Number =5;
for (var i:Number = 0; i < maxLength; i++){
trace(mcScreenShots['mcScreen'+ i])
}
and I am still getting this:[object mcScreen0_2]
[object mcScreen1_6]
[object mcScreen2_9]
[object mcScreen3_12]
[object mcScreen4_15]
and I do not have a movieclip or symbol by those names in my library.
Any help?:confused:
kdittyr
05-09-2008, 03:14 AM
Well, mcScreenShots is an array of what? It isn't tracing out what you want to see because it is an array of objects... maybe try:
var maxLength:Number =5;
for (var i:Number = 0; i < maxLength; i++){
trace(mcScreenShots['mcScreen'+ i].name);
}
I imagine these were created dynamically, I usually add a name to all objects created in a loop as it helps me when I run into problems like this.
elaniobro
05-09-2008, 03:22 PM
Well, mcScreenShots is an array of what? It isn't tracing out what you want to see because it is an array of objects... maybe try:
var maxLength:Number =5;
for (var i:Number = 0; i < maxLength; i++){
trace(mcScreenShots['mcScreen'+ i].name);
}
I imagine these were created dynamically, I usually add a name to all objects created in a loop as it helps me when I run into problems like this.
kdittyr, thank you very much, and you too slowburn. That worked!
Now I can proceed. Cheers!:):cool::)
kdittyr
05-12-2008, 06:11 PM
Awesome! Glad to hear you got it working :)
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.