• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

diapatchEvent class

Hello,
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.




package
{
   import flash.events.Event;
 
  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)
    {
      super(type);
      _time = time;
      _duration = duration;
    }
  }  
}

Open in new window

0
eb110k
Asked:
eb110k
  • 2
  • 2
1 Solution
 
blue-genieCommented:
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?

0
 
eb110kAuthor Commented:
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.
0
 
blue-genieCommented:
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();
myDate.getDay();

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.

0
 
eb110kAuthor Commented:
Thank you for your advise.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now