Photoshop Tutorials, Flash Tutorials, 3Ds Studio Max Tutorials, Web Design Tutorials |
![]() |
|
:: Free Website Templates
Welcome To WebDesignTutorials.net Flash Tutorials Area - Flash MX Event Model
One of my favourite new features of Flash MX, has to be the new event
model, it just makes life so much easier and makes coding so much more
fun and so much more organised. If you dont know much about it, then
now is the time to find out, you really are missing out, but no doubt
you are already using it without even realising. This article will
hopefully help everybody that reads it, whether you are a beginner or a
flash super user, understand the flash event model, and help you to use
it. I think the best way to explain something new to somebody so that
they can learn from it is to compare the subject with something that
humans can relate to in their everyday lifes; A real world Analogy, so
this article uses analogies to convey some of the concepts...
What you need to know: To understand some of the explanations and terms used in this article, you need to know certain things about flash, firstly you need to understand that flash is now Object Oriented and therefore you should already have a basic understanding of Object Oriented Programming with flash, if you can answer the questions below, you will can continue to read this article and hopefully you should understand everything, otherwise you should checkout this excellent site that gives an in-depth explanation of Object Oriented Programming for flash: Robin Debreiul What is an object? Event Description / Event Handler Mouse is moved/onMouseMove Listeners:Listeners are user defined actionscript objects that are registered with specific departments of the flash players news bulletin, because they are interested in seeing the news that those departments broadcast. After an object has registered interest with one of the news bulletin departments, whenever an event occurs, that the news bulletin department is looking out for, a news broadcast is sent out and the registered object will receive it. So in actionsript terms, a listener is an object that contains event handlers, the object registers with a specific predefined object so that it can receive the events related to that predefined object. Using the Listener Methods:We have methods that allow us to register and unregister our interest in the broadcasts from the news bulletin departments. To register an objects interest with a news bulletin department we use the addListener method and to unregister our interest with a news bulletin department we use the removeListener method. Here is the process we go through to register our interest with a news bulletin departments broadcast, in this example our object is interested in the Mouse objects broadcast: //create a new empty object Mouse.removeListener(myobject); So in actionsript terms, now, whenever a Mouse event occurs, the object named ‘myobject’ will be notified that a Mouse event occurred and which Mouse event occurred. Adding event handlers to objects:For the empty object we created named ‘myobject’ to act on the broadcasts it receives from the news bulletins Mouse department, we need to tell it what to do when a specific event occurs, so as you should now know, we have to define event handlers for the object. To define an event handler that will output the words “Mouse was moved” to the output window, whenever the mouse is moved, we would use the onMouseMove event handler, as follows:
//create a new empty object //create a new empty object
Key.addListener(myobject) //define the onKeyDown event handler for our object myobject.onKeyDown=function(){ trace(“Key was pressed”); }So, lets explain what happens now when the user clicks his mouse in actionscript terms. Whenever the user clicks his mouse, the Mouse object notifies the object named ‘myobject’ that the onMouseDown event has occurred and then the onMouseDown event handler is triggered, which in turn runs the code that outputs the words “Mouse was moved” to the output window. Movieclips and Buttons listen automatically:As mentioned previously, for an object to receive event notification it has to be registered with the predefined actionscript object that provides those events. Since Flash 5, Movieclips were objects that inherited from the Movieclip class, now, in Flash MX, Buttons are objects that inherit from the Button class. All instances of the Moveclip class have their interest registered with the Movieclip news broadcast automatically and all instances of the Button class have their interest registered with the Button news broadcast automatically. This means that you do not need to explicity use the addListener method, for a Movieclip to be notified of any Movieclip events, and the same goes for Buttons. So it is possible to do the following: //create a new movieclip on the _root timeline onClipEvent(mouseMove){ on(press){ Yourbutton.onPress=function(){ Advantages of using the new event model:The first thing that you gain by using the Flash MX event model as opposed to the old event model is that you can change your event handlers at any time, thus changing the function that is executed when an event occurs. Also, because an event handler is now just a property of an object, it can also be deleted thus saving cpu usage, which could not be achieved without a bit of trickey once the movie was running with Flash 5. In flash 5 you couldn’t attach a movieclip from the library using the attachMovie method and then assign an event handler to it because the onClipEvent() event handler had to be defined on the movieclip as opposed to inside of it, at authoring time. It is now very simple to achieve that in Flash MX. Finally the new Flash MX event model is a lot cleaner, easier to use and more organised than the old event model that Flash 5 provided. Author: Guy Watson
|
|
|||||||||||||||||||||||||||||||||
Premium Partners |
| Free Website Templates - Flash templates, Affordable Website Design, Website Templates, Website Redesign, Custom Website Design, Web Design Tutorials, Flash Tutorials, Promotion Tutorials - that is what we do. Metamorphosis Design Studio offers quality, free and low cost web site templates for your business and personal life, we also offer affordable web design and site re-design. |
| Vertex Website Tempales - It saves tones of time and money to use pre-made web designs to build your web site. You need a web site but you don't want to pay thousands dollars to professional web design companies? Our web templates is just for you! They are designed to be easilly edited by your favorite html editor, like MS FrontPage |
| Photoshop Tutorials - Learn how to build stunning web pages using Adobe Photoshop, Macromedia Flash MX and 3D Studio Max software. The step-by-step approach makes it so easy, that even beginners can produce great web pages. Get started with these tutorials covering everything from page layout to content tips. |
Free website templates and paid web templates are great tools to make your websites look perfect! You will save time and money with our flash templates and free website templates
Our visitors are satisfied with the quality of our free and paid website templates! Please visit our free website templates and paid website templates sections. We offer free web templates, free web layouts, free web page templates and other stuff for free download. All templates come with the html and external css file so you may easily edit HTML with your favorite HTML editor. Feel free to download our free web templates for your personal websites. Terms of use depend upon the website template vendor. |
| Home | Submit Tutorial | Top Sites | Free Templates | Website Templates | Privacy Policy | Contact Us |
| All Right Reserved by WebDesignTutorials.net |