dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Call document class function from a movieclip on the timeline

  1. #1
    Member
    Join Date
    Mar 2004
    Posts
    51

    Call document class function from a movieclip on the timeline

    Once again, I'm impressed with how obtuse everything must be.

    I have a function defined in my document class that I want to call on a framescript of a movieclip placed on a timeline. Of course, left to itself it's "undefined", and I can't figure out how to reference parent/root/document class.

    This should be a simple one for someone to help me with

  2. #2
    Member
    Join Date
    Dec 2006
    Posts
    52
    If you have a document class why are you writing code on the timeline? You should possibly try to start writing seperate classes for your movieclips, as issues like this become simpler to solve.

    but anyway, if the movieclip is directly placed on the stage you could try writing in the movieclips framecode: this.parent.myDocClassFunction();
    as this.parent would be the stage which (I think) would link to your document class.
    (I may be wrong, as I dont really use timeline code, but its worth a try)

  3. #3
    Member
    Join Date
    Mar 2004
    Posts
    51
    Unfortunately that's one of the first things I tried, and that doesn't work. Thanks for the help though!

    Any other ideas?

    I'm writing frame code because I have created an animation in flash that I want to play out before the actual code kicks in. I pine for the simpler days of AS2.

    As a side note, I tried dispatching an event at the frame, but that didn't work.

  4. #4
    Member
    Join Date
    Dec 2006
    Posts
    52
    hmmm well you could controll it all from your document class (although this possibly an unnecessarily long way of solving your problem, but the only way i can currently think of).

    so in the constructor of your doc class:

    Code:
    public function DocClass()
    {
          this.addEventListener(Event.ENTER_FRAME, testAnimationDone);
    }
    the instance name of the movieclip that you have placed on the stage in this example is called animatedClip.

    Code:
    private function testAnimationDone(e:Event)
    {
          if(this.animatedClip.currentFrame == this.animatedClip.totalFrames)
          {
                this.animatedClip.stop(); //stops your clip looping, you could put this in the last frame of animatedClip, but this way puts all code in the doc class
                this.removeEventListener(Event.ENTER_FRAME, testAnimationDone);
                myDocClassFunction(); //this is the function you have been trying to call
          }
    }

    this method of doing thngs puts ALL your code in your document class, making it easiear to find later.

  5. #5
    Member
    Join Date
    Mar 2004
    Posts
    51
    That's an interesting method! I'll check it out - thanks!

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