A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Creating a custom class which can return a custom event

  1. #1
    Developer
    Join Date
    Apr 2007
    Location
    UK
    Posts
    324

    Creating a custom class which can return a custom event

    Just as it says on the tin. I want to create a class which will do its work, and when it's done, generate an event back to my movie.

    I want to use my custom class like this :

    var test:Main = new Main()
    test.onDone = function() {
    // blah blah
    }

    Is there any sample classes which do this?

    Im tearing my hair out over this!

  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    All you need to do is define onDone as a Function variable in Main
    Code:
    ...
    public var onDone:Function;
    ...
    and then when it does the things you need, in whatever Main method that does those things (note this cannot be the constructor if a synchronous process since it will complete before you have a chance to define onDone), call it:
    Code:
     if (onDone) onDone();
    In ActionScript 3, however, its more common to use EventDispatcher and addEventListwner/dispatchEvent

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