Events are serious business in Actionscript– When the user clicks, double clicks, focuses on an object, right clicks, etc., an event is generated. Dealing with those events is a large part of successful Actionscript programming. In this video, Mark will teach you the basics of events and also take a look at the event object and how you can use it to write more efficient code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="500" minHeight="400" creationComplete="init()"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <fx:Script> <![CDATA[ private function init() { btnOne.addEventListener(MouseEvent.CLICK, clickOne); btnTwo.addEventListener(MouseEvent.CLICK, clickOne); } private function clickOne(event:MouseEvent) { //txtResult.text = "Button One has been clicked"; var id = event.target.id; if(id == "btnOne") { txtResult.text = "Button One has been clicked"; } else { txtResult.text = "Button Two has been clicked"; } } /* private function clickTwo(event:MouseEvent) { txtResult.text = "Button Two has been clicked"; } */ ]]> </fx:Script> <s:Button x="9" y="10" label="One" id="btnOne"/> <s:Button x="10" y="39" label="Two" id="btnTwo"/> <s:TextArea x="156" y="10" height="50" id="txtResult"/> </s:Application> |
Tags: Actionscript, events, Flash Builder, Flash Professional, Flex, MXML, tutorial, Video


