A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Syntax help with accessing instance name, dynamically...

  1. #1
    NZ nizamm's Avatar
    Join Date
    Nov 2001
    Location
    Middle of the East.
    Posts
    643

    Syntax help with accessing instance name, dynamically...

    Hey guys, n00b needs help,

    I need to play a movie clip whose instance name is set into a dynamic text field. Say, if I were to have a dynamic text field named 'holder', containing the instance name 'mc1', how would I play it?

    Considering incorrect syntax, this is what I'm trying to do:

    Code:
    _root.holder.text.gotoAndPlay(10);  //which is incorrect
    alternatively,

    Code:
    var instance_name = _root.holder.text;
    _root.instance_name.gotoAndPlay(10); // which is also incorrect.
    Hope I'm making sense. That ^ is what I wanna do but I'm looking for the right syntax.

    HALP!
    What's that? You haven't seen my site yet?? Here you go - Click Me!

  2. #2
    Member
    Join Date
    Nov 2006
    Posts
    69
    I asume this is what you mean...
    (Pseudo-example)

    You have made a text field
    you have converted it to a movie instance and named it textField
    you have entered the movie and added frames and stuff.

    so you have tried
    _root.textField.gotoAndPlay(10)
    that failed.

    This is what I usualy do as gotoAndPlay tends to be tempermental...
    Inside the movieclip
    onClipEvent (load) {
    function goTo10() {
    gotoAndPlay(10);
    }
    }

    Then to go to the frame simply type textField.goTo10();

    I am sure there are more eligent ways to do it but it works for me.

  3. #3
    NZ nizamm's Avatar
    Join Date
    Nov 2001
    Location
    Middle of the East.
    Posts
    643
    Thanks for the post del, but a bit different from what you've said. Let me try to give a clearer picture.

    I have a dynamic text field with an instance name of its own called 'txt1'.

    I have a movie clip with its own instance name as 'mc1'.

    Both objects are on the root of the timeline.

    Now, I want to play 'mc1', once I assign txt1.text = mc1; I do not want to play 'mc1' directly by coding _root.mc1.play(); Instead, I want it to wait for the instance name to pop up in 'txt1' to play there and then. Currently I have a conditional statement which is hard coded to each of the instance names. I do not want that and hence am trying to directly access the 'mc1' via 'txt1' which makes the code flexible to play MCs of any instance name.

    Am I making sense, anyone?
    What's that? You haven't seen my site yet?? Here you go - Click Me!

  4. #4
    Member
    Join Date
    Nov 2006
    Posts
    69
    So you want a movie to load that is named in txt1....

    There is an obvious problem in that there is no 'onChange' event in flash so you will either have to make a list of usable movie names or make a button to use when it is right. I'd use the button method.

    // txt1 = text field
    // button1 = button

    function(loadmov) {
    _root.createEmptyMovieClip("mc"+counter,_root.getN extHighestDepth());
    loadmovie("_root.mc"+counter,_root.txt1.text);
    counter ++;
    }

    button1.onPress = function(success) {
    _root.loadmov();
    }

    Will that do?

  5. #5
    NZ nizamm's Avatar
    Join Date
    Nov 2001
    Location
    Middle of the East.
    Posts
    643
    Quote Originally Posted by deldelfarrom
    So you want a movie to load that is named in txt1....

    There is an obvious problem in that there is no 'onChange' event in flash so you will either have to make a list of usable movie names or make a button to use when it is right. I'd use the button method.

    // txt1 = text field
    // button1 = button

    function(loadmov) {
    _root.createEmptyMovieClip("mc"+counter,_root.getN extHighestDepth());
    loadmovie("_root.mc"+counter,_root.txt1.text);
    counter ++;
    }

    button1.onPress = function(success) {
    _root.loadmov();
    }

    Will that do?
    Well I am using 'onEnterFrame' to check that onChange event. Besides I see you got a counter attached as a string to the movie clip. My 'mc1' name was just an example. In reality, my instance names are all different and don't have a uniform name. All I need to do is read a string from the dynamic text file which has the SAME name of an instance present in my movie, to do whatever action I require it to do.

    I've attached a fla. Run it and see what I'm trying to do. All I want now is to remove the switch cases for the 3 rectangles below. I do not want to restrict the conditions to just red, yellow and green, but instead looking for a solution which would simply read whatever string I have to play the corresponding movie clip, which in this case, I have named them as per color.

    Now, am I making sense?
    Attached Files Attached Files
    What's that? You haven't seen my site yet?? Here you go - Click Me!

  6. #6
    NZ nizamm's Avatar
    Join Date
    Nov 2001
    Location
    Middle of the East.
    Posts
    643
    BooHoo! Help!
    What's that? You haven't seen my site yet?? Here you go - Click Me!

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