MTWK
07-13-2009, 05:04 PM
Okay, here's the problem.
!) With a loop, I've created 6 movie clips.
2) Named each movie clip with string "image" + the current index of the loop
3) As I go through the loop, I loaded an image into each movie clip.
This seems to all work fine. When I run a display list code, I can see my movie clips all named. Here's the code:
<code>
//Sets up the array of images- must be changed for each flash movie
var imagePath:Array = new Array("ImagesWallPack/1009-T.jpg", "ImagesWallPack/1011-T.jpg", "ImagesWallPack/1012-T.jpg", "ImagesWallPack/1013-T.jpg","ImagesWallPack/1014-T.jpg","ImagesWallPack/1017-T.jpg" );
//var imageClipsHolder:Array = new Array();//Is an array to hold the required number of movie clips
var totalImages:Number = imagePath.length;//Calculates how many images there are
//Create placeholder movieclips
for (var index = 0; index < totalImages; index++) {//Creates the actual movie clips to hold the images
//Create a new holder
var imageClips:MovieClip = new MovieClip();
imageClips.name ="image" + index;
var imageLoader:Loader = new Loader();
//imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
imageLoader.load(new URLRequest(imagePath[index]));
imageClips.addChild(imageLoader);
//Position the various holders
imageClips.x = index + 30;
imageClips.y = index + 30;
//Add the holder to the stage
addChild(imageClips);
}
// Temporary function that shows the movie layers in the movie: debugging purposes
function showChildren(dispObj:*, indentLevel:Number):void {
for (var i:int=0; i<dispObj.numChildren; i++) {
var obj:DisplayObject = dispObj.getChildAt(i);
if (obj is DisplayObjectContainer) {
trace(padIndent(indentLevel), obj.name, obj);
showChildren(obj, indentLevel + 1);
} else {
trace(padIndent(indentLevel) + obj);
}
}
}
showChildren(stage, 0);
function padIndent(indents:int):String {
var indent:String = "";
for (var i:Number = 0; i < indents; i++) {
indent += " ";
}
return indent;
}
</code>
Here's the trace output:
root1 [object MainTimeline]
image0 [object MovieClip]
instance2 [object Loader]
image1 [object MovieClip]
instance5 [object Loader]
image2 [object MovieClip]
instance8 [object Loader]
image3 [object MovieClip]
instance11 [object Loader]
image4 [object MovieClip]
instance14 [object Loader]
image5 [object MovieClip]
instance17 [object Loader]
So the display list seems to indicate that I have 6 movie clips on the stage.
PROBLEM:
When I try to target the movie clips by name in adding the following code for example:
image2.apha = 0;
I get an error:
1120: Access of undefined property image2.
What I don't get is: image2 is a movieclip and a movieclip has a property of alpha?
What am I doing wrong?
!) With a loop, I've created 6 movie clips.
2) Named each movie clip with string "image" + the current index of the loop
3) As I go through the loop, I loaded an image into each movie clip.
This seems to all work fine. When I run a display list code, I can see my movie clips all named. Here's the code:
<code>
//Sets up the array of images- must be changed for each flash movie
var imagePath:Array = new Array("ImagesWallPack/1009-T.jpg", "ImagesWallPack/1011-T.jpg", "ImagesWallPack/1012-T.jpg", "ImagesWallPack/1013-T.jpg","ImagesWallPack/1014-T.jpg","ImagesWallPack/1017-T.jpg" );
//var imageClipsHolder:Array = new Array();//Is an array to hold the required number of movie clips
var totalImages:Number = imagePath.length;//Calculates how many images there are
//Create placeholder movieclips
for (var index = 0; index < totalImages; index++) {//Creates the actual movie clips to hold the images
//Create a new holder
var imageClips:MovieClip = new MovieClip();
imageClips.name ="image" + index;
var imageLoader:Loader = new Loader();
//imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
imageLoader.load(new URLRequest(imagePath[index]));
imageClips.addChild(imageLoader);
//Position the various holders
imageClips.x = index + 30;
imageClips.y = index + 30;
//Add the holder to the stage
addChild(imageClips);
}
// Temporary function that shows the movie layers in the movie: debugging purposes
function showChildren(dispObj:*, indentLevel:Number):void {
for (var i:int=0; i<dispObj.numChildren; i++) {
var obj:DisplayObject = dispObj.getChildAt(i);
if (obj is DisplayObjectContainer) {
trace(padIndent(indentLevel), obj.name, obj);
showChildren(obj, indentLevel + 1);
} else {
trace(padIndent(indentLevel) + obj);
}
}
}
showChildren(stage, 0);
function padIndent(indents:int):String {
var indent:String = "";
for (var i:Number = 0; i < indents; i++) {
indent += " ";
}
return indent;
}
</code>
Here's the trace output:
root1 [object MainTimeline]
image0 [object MovieClip]
instance2 [object Loader]
image1 [object MovieClip]
instance5 [object Loader]
image2 [object MovieClip]
instance8 [object Loader]
image3 [object MovieClip]
instance11 [object Loader]
image4 [object MovieClip]
instance14 [object Loader]
image5 [object MovieClip]
instance17 [object Loader]
So the display list seems to indicate that I have 6 movie clips on the stage.
PROBLEM:
When I try to target the movie clips by name in adding the following code for example:
image2.apha = 0;
I get an error:
1120: Access of undefined property image2.
What I don't get is: image2 is a movieclip and a movieclip has a property of alpha?
What am I doing wrong?