Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cannot target a movie clip name created with AS

    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 objisplayObject = 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?

  • #2
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Solution

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •