dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: passing dynamic variables

  1. #1
    Junior Member
    Join Date
    Jun 2001
    Posts
    7
    Hi,

    I'm having some problems retaining variables created dynamically using duplicateMovieClip. I've looked through this code over and over, but can't find anything wrong!

    On frame 1 I have
    Code:
    i = 5;
    while (--i > 0) {
    	name = "box" + i;
    	box.duplicateMovieClip(name, i);
    	loadMovie ("image"+i+".jpg", name);
    	this[name]._x = 0;
    	this[name]._y = i * 60;
    	this[name].menuID = "image" + i;
    }
    On the movieclip "box" I have:
    Code:
    onClipEvent (load) {
    	trace (menuID);
    }
    on (release) {
    	trace (menuID);
    }
    The crux is, when I test the movie, I get four "boxes" with the appropriate image in them and the output is

    undefined
    image4
    image3
    image2
    image1
    undefined
    undefined
    undefined
    undefined

    I would have expected the output to be image4, image3, image2, image1, but where are the undefined's coming from? When I click on any of the resulting box movieclips, I get "undefined" from its trace rather than, say, "image3".

    Where did I go wrong? Is there another way to do this?

    Thanks a plenty for the help!

  2. #2
    the JesterTerrestrial Himself stumpy's Avatar
    Join Date
    Apr 2000
    Location
    The C.O.G. - County Of Grey
    Posts
    203
    hi... I'm not quite sure but it looks like there is a problem with the var menuID.
    Where is it being set...does it need to be set before the movie clips loads?

    Good luck

  3. #3
    Junior Member
    Join Date
    Jun 2001
    Posts
    7
    Thanks for the suggestion Stumpy.

    I'm not sure where I can set the var menuID in advance because it is created as the "box" movieclip is duplicated. However, I tried setting menuID="booger" on the box MC just before the trace, and I end up with booger nine times on the output.

    Does anyone know why this would output booger nine times? The code should only generate 4 "box"'s right?

    Thanks for the help

  4. #4
    the JesterTerrestrial Himself stumpy's Avatar
    Join Date
    Apr 2000
    Location
    The C.O.G. - County Of Grey
    Posts
    203
    yes it looks like it should only generate 4 lines.
    Maybe you are missimg a stop action?


    this is just guessing again but here is what I think.

    Looks like there is an instance of the movie clip on the stage already? yes no?? if so the code on this one will go off giving you your first undefined before it is set in the main loop....then I as the loop goes the MenuID is set usin "i" and goes throug image 4,3,2,1...then the last undefineds?? Must be a missing stop action.

    Maybe is has something to do with the Var being located in two differetn timelines.

    If anyone else has any ideas, lets hear them. Good luck.
    Stumpy

  5. #5
    www.intensewd.com
    Join Date
    Apr 2002
    Location
    Australia
    Posts
    450
    hey!

    had a quick little peek at your code...i think the problem might be this:
    onClipEvent (load) {
    trace (menuID);
    }
    on (release) {
    trace (menuID);
    }
    the onClipEvent assumes you're referring to a variable/instance within the clip.

    on (release) assumes you're referring to a variable/instance on the main timeline.

    try:
    Code:
    onClipEvent (load) {
    	trace (menuID);
    }
    on (release) {
    	trace (this.menuID);
    }
    or
    Code:
    onClipEvent (load) {
    	trace (menuID);
    }
    on (release) {
    	trace (InstanceName.menuID);
    }
    where InstanceName is the instance name of the mc!

    Cheers,
    Ben

  6. #6
    Junior Member
    Join Date
    Jun 2001
    Posts
    7
    Thanks for the suggestions everyone. I've placed stop() actions on every frame and tried changing each of the call variables to this.myVariable but I still get the same output.

    However, the first undefined must come from the instance of box already on the stage. Thanks stumpy.

    For some reason, the menuID variables start off fine, but then they turn into undefined's. Why would that happen?! Does the loading of data (ie, when the box MC recieves the jpeg) change the variable name?

    Thanks for these great suggestions. Keep them coming if there are anymore!

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center