dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Annoying problem with dynamic reference to timeline function

  1. #1
    Junior Member
    Join Date
    Mar 2009
    Posts
    9

    Annoying problem with dynamic reference to timeline function

    Hello,

    I'm having a little issue that is beating me, I have a situation like below,

    Code:
    class Example extends MovieClip {
    
       private var _index:Array = new Array();
    
       public function Example() {
            this._index.push('name');
            this.output();
       }
    
       public function output() {
          var _value:Object = this._index.pop();
          _value.play();
       }
    
    }
    I'm trying to dynamically obtain the name of a movieclip instance and then play it, however I keep getting errors. I even tried casting the variable _value as a Function, but that didn't work, tried wrapping it in array brackets such as

    Code:
    [_value].play();
    and that still didn't work. Any suggestions will be appreciated..

  2. #2
    Senior Member Computer Dork's Avatar
    Join Date
    Mar 2001
    Location
    St. Louis
    Posts
    1,026
    I run into this issue a bit too - one quick way(hackish) to solve - if the class is attached to your library symbol via linkage, set up an init($name:String) method that you can easily send the name from the document class or main timeline. If not, just pass it in to the constructor and set a class var __name:String equal to it.

  3. #3
    Junior Member
    Join Date
    Mar 2009
    Posts
    9

    Hmm..

    Hi, thanks for the response. My class serves as my Document class, but a little more clarification on your suggestion would help. I didn't really understand the second point you were making.

    Thanks

  4. #4
    Senior Member Computer Dork's Avatar
    Join Date
    Mar 2001
    Location
    St. Louis
    Posts
    1,026
    so you basically need to know the name of the root? I don't understand...

  5. #5
    Junior Member
    Join Date
    Mar 2009
    Posts
    9
    Not actually, the flash movie I am creating acts somewhat like a powerpoint slideshow, so I have named the various slides with certain instance names. Based on the current slide, I want to dynamically cause the slide to play its timeline, thus animating it into view.

    I hope now you get a clearer picture of what I am trying to achieve.

    Thanks

  6. #6
    Junior Member
    Join Date
    Mar 2009
    Posts
    9
    I found a solution to my problem and thought that I should share it with the rest of the community. I was looking around on the internet and came across an actionscript 3 hack that would allow you reference any movieclip on the timeline in an actionscript 2 way by simply;

    Code:
    //yourMovieClip is the name of the MovieClip you want to access
    root["yourMovieClip"].play();
    In this way you can dynamically assign the name of your MovieClip and perform any action on it, e.g.

    Code:
    var dynamicRef:String = "main";
    root[dynamicRef].play();
    and it'll work.....

    Hope someone finds this useful.....

  7. #7
    Senior Member Computer Dork's Avatar
    Join Date
    Mar 2001
    Location
    St. Louis
    Posts
    1,026
    that isn't really a 'hack' per se... but if you are going that route, why not just throw it in a function?

    function playSlide($ref:String):void
    {
    root[$ref].play();
    }

    Then all you have to do is call it -

    playSlide("main");

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