SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get a movie clip's instance name dynamically?

    hey, i'm making a questionnaire in flash, and to make my script more reuseable, i need to find out if there's a way to get an movie clip's instance name dynamically.

    any takers?

  2. #2
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your using Flash 5 you could try using the _this.movieClip referer - that way you don't need the actual name

  3. #3
    SitePoint Enthusiast appy's Avatar
    Join Date
    Feb 2002
    Location
    UK
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another way is to use the attachMovieclip command which allows you to dynamically specify the name of the movie clip.

    Create an empty movieclip with whatever name you want, place it on the stage at the top left corner of where you want your attached movieclip to appear on the stage and, using the instance panel, give it a (unique identifier) name, e.g. myContainer.

    Create the movie clip you want to dynamically name but do not place it on the stage. Within the Library, right-click on the movieclip that you just made and go down to linkage. A small window will appear. Click on Export this symbol, and enter a unique identifier, e.g. myMovieclip.

    Then use a bit of actionscript to attach the movieclip, known through linkage as myMovieclip, to the empty clip you created, known as myContainer, and give it the dynamic name you want.

    For example, if you simply want the clip to appear on the stage at a particular point in the timeline, click in the particular keyframe in your timeline (should be in a layer called 'actions' or similar if you like keeping things neat) and add the script like below:

    count = 1;
    myContainer.attachMovie( "myMovieclip", "newClip" add count, 1 );

    In plain english this says: attach a movie to the "myContainer" movieclip, use "myMovieclip" from the library as the movie to attach, make a name for it by concetating "newClip" and the variable "count" and stick it on level 1.

    With this you will end up with an instance of you movie clip (myMovieclip) positioned with it's upper-left point at the position of myContainer, which is named "newClip1". You can then reference "newClip1" using your actionscript in the normal way.

    Of course the variable count can change and so the name of the movieclip you are placing on the timeline using actionscript can change.


  4. #4
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    concatenation of a part of a variable

    on (release) {

    for (i=1; i<=4; i++) {

    if (_root.survey.filled[i]_alpha=100) {

    _root.survey.filled1._alpha=100;

    }


    }

    }

    i'm trying to get the _root.survey.filled to be 1,2,3,4 depending on the point it is in the loop. i can't remember what it is exactly to do this. any help?

  5. #5
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried using eval() some thing like....

    Code:
    for (i=1; i<=4; i++) { 
    
    if (eval(_root.survey.filled[+i]._alpha) = 100) { 
    
    trace("woohoo");
    
     } 
    }

  6. #6
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm, do you mean:

    if (_root.survey["filled"+i]._alpha=100) {
    }

    ?

    That compares _root.survey.filled1, _root.survey.filled2 and so on.

  7. #7
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahhh yer thats it using eval...

    Code:
    if (eval(_root.survey["filled"+i]._alpha) = 100) { 
    }

  8. #8
    Pixel Junkie flux's Avatar
    Join Date
    Apr 2001
    Location
    Brussels Belgium
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there's no need to eval the
    Code:
    _root["string"+var]._alpha=100;
    it works a lot faster than the

    Code:
    eval("_root.string"+var)._alpha=100;
    as it takes the Flash interpreter less steps to perform the first line of code.

  9. #9
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Flux has it right. No eval needed.

    If you're using an if statement you might wanna use == instead of = though. Just noticed that Spidergrant caused a 3-post error chain.


Bookmarks

Posting Permissions

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