diapatchEvent class

Posted on 2009-04-27
Last Modified: 2013-11-11
I'm trying to understand how dispatchEvent class works with static const variable based on code below.

Let's say that dispatched events as shown below.

dispatchEvent(new TestDispatch(TestDispatch.TIME, videoTime);
dispatchEvent(new TestDispatch(TestDispatch.DURATION, videoDuration);
(videoTime has value of current video's time, videoDuration has total duration of video)

I've learned that constructor function of TestDispatch class executed for both event dispatching as long as the public contants declaired.

My question is what is the meaing of value of static constant "video_time", "video_duration"?
Looks like it has nothing to do with value of static constant whether it's "1", "hello" and ....
If it has something to do with dispathing event, in what case is it?

Please some one give me clear answer.
I'm still very new to actionscript and it's very confuses me.

Thank you.





  public class TestDispatch extends Event


    public static const TIME:String = "video_time";

    public static const DURATION:String = "video_duration";

    protected var _time:Number;

    protected var _duration:Number;


    public function TestDispatch(type:String, time:Number, duration:Number)



      _time = time;

      _duration = duration;




Open in new window

Question by:eb110k
    LVL 39

    Expert Comment

    Hi, I'm struggling to understand  your question.

    first of all the dispatchEvent() is a method of the EventDispatcher Class - it's not a class.

    then your TestDispatch constructor has 3 parameters but when you do your dispatchEvent (new TestDispatch ()) - you have 2 parameters?


    Author Comment

    I'm sorry that I confused you.
    TestDispatch construction function has 2 arguments and duration:Number should be duration:Number = -1.

    My question is what's roll for static cost's value?
    In this case:
    "video_time" and "video_duration"

    I've read and watched a lot of tutorials for dispatching event and I think I understood basic structure and process of dispatching event. But I still don't understand what value of static const will do.
    May be it's really silly question, but I'm very new to Actionscript 3.0 and really would like to know.

    Please advise.
    Thank you.
    LVL 39

    Accepted Solution

    do you mean why would you make something static constant?

    a static variable means it belongs to the Class and not to an instance of a class.

    for example the built in Date class has a parse method and a getDay method. the parse method is static whereas the getDay method is not.

    so you use Date.parse() but in order to use getDay() you need to create a new Date object i.e.

    var myDate:Date = new Date();

    why would you do that - I'm sure there's a correct answer but personally I hardly ever make anything static.
    A constant is just something that is never going to change during it's lifespan in your code.

    a normal example is the value of PI - that's a static - it doesn't change so you can make that a static variable.


    Author Closing Comment

    Thank you for your advise.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
    I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
    The goal of the tutorial is to teach the user how to how to record live broadcast.
    The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now