...

View Full Version : Cannot target a movie clip name created with AS



MTWK
07-13-2009, 06: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?

iainasmith
06-01-2011, 02:17 PM
Hello, few years on to reply!

The answer is a simple one! - been racking my brains for about 3 hours and just come to me...

You need to set the LINKAGE property of the movieclip in the library panel to a class name else it won't export when you trace it...

Go to the object in the library and right click and choose properites and then tick Export for Actionscript on, it will then put the movieclip name in the Class field... click ok job done

Hope that helps



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum