![]() |
![]() |
||||||
|
|||||||
| Tags: event, program |
![]() |
|
|||
|
why the main application can not listen the event from the component?
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*" creationComplete="initApp()"> <mx:script> <![CDATA[ import Events.MyEvent; import flash.events.Event; private var newevent:MyEvent = new MyEvent(); private function initapp():void{ newevent.addEventListener(MyEvent.TestEvent, myEventHandler); } private function myEventHandler(e:Event):void{ trace("the main application catch the event"); } ]]> </mx:script> <local:TestEventCom /> </mx:Application> <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="400" height="300"> <mx:script> <![CDATA[ import Events.MyEvent; private var newevent:MyEvent = new MyEvent(); private function btnclick():void{ newevent.dispatch(); showarea.text = "I detect the event"; } ]]> </mx:script> <mx:TextArea id="showarea" x="112" y="124" /> <mx:Button id="eventButton" click="btnclick()" label="DisPatchEvent" /> </mx:TitleWindow> package Events{ import flash.events.Event; import flash.events.EventDispatcher; public class MyEvent extends EventDispatcher{ public static const TestEvent:String = "newevent"; public function MyEvent(target:IEventDispatcher=null){ super(target); } public function dispatch():void{ dispatchEvent(new Event(TestEvent)); trace("dispatch a new event"); } } } |
| Sponsored Links |
|
|||
|
Adobe Newsbot hopes that the following resources helps you. NewsBot is experimental and any feedback (reply to this post) on its utility will be appreciated:
Flex 3 - TitleWindow layout container: <?xml version='1.0'?> <!-- containers\layouts\myComponents\MyLoginForm.mxml --> <mx:TitleWindow xmlns:mx='http://www.adobe.com/2006/mxml'> <mx:Script> <! Link: http://livedocs.adobe.com/flex/3/html/layouts_12.html Creating an undraggable TitleWindow container in Flex at Flex Examples: TitleWindow; import mx.controls.Label; import mx.core. .... Changing the background color of a disabled TextArea control in Flex Link: http://blog.flexexamples.com/2008/08...ainer-in-flex/ Flex 3 - Form, FormHeading, and FormItem layout containers: <?xml version='1.0'?> <!-- containers\layouts\FormSimple.mxml --> <mx:Application ... Flex positions children vertically to the right of the FormItem label. Link: http://livedocs.adobe.com/flex/3/html/layouts_08.html Creating custom dialog boxes using the PopUpManager and: addChild(label); PopUpManager.addPopUp(titleWindow, this, true); PopUpManager. ... Super Awesome Component Set for Flex 3' layout='vertical' width='480' Link: http://blog.flexexamples.com/2007/08...indow-classes/ Using the addPopUp() method -- Flex 2.01: TitleWindow; import flash.events.*; import mx.managers. ... Whatever text you type in the TextArea is stored in a Label control in the application when the Link: http://livedocs.adobe.com/flex/201/h...ts_065_51.html Changing the close button skin on a Flex TitleWindow container at: Or, you can create a Flex Componet skin using the Flex Component Kit and Flash CS3 where the ... xmlns:mx='http://www.adobe.com/2006/mxml' layout='vertical' Link: http://blog.flexexamples.com/2007/12...dow-container/ Disclaimer: This response is generated automatically by the Adobe NewsBot based on Adobe [L=Community Engine]http://community.adobe.com/ion/search.html[/L]. |
|
|||
|
Hi,
Firstly you are adding event listener on two different instances of an object. An object will dispatch event to its listeners only. Secondly in your MyEvent class you are dispatching a Event, which has bubbles property set to false. If bubbles property is set to true, then all the parents of an component can handle the event. In your case if the TextEventCom fires a event which has bubbles set to true then the parent can handle the event. I am assuming that you want to throw a custom Event from the child (TestEventCom), which you want to handle in the parent. If that is the case please check out the sample below. If that is not what you want, kindly ignore the code sample below. Hope this helps. Main application <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*" creationComplete="initApp()"> <mx:Script> <![CDATA[ import Events.MyEvent; import flash.events.Event; private function initApp():void{ this.addEventListener(MyEvent.TestEvent, myEventHandler); } private function myEventHandler(e:Event):void { this.removeEventListener(MyEvent.TestEvent, myEventHandler); trace("the main application catch the event"); } ]]> </mx:Script> <local:TestEventCom /> </mx:Application> Child component <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="400" height="300"> <mx:Script> <![CDATA[ import Events.MyEvent; private function btnclick():void { var newevent:MyEvent = new MyEvent(MyEvent.TestEvent); dispatchEvent(newevent); showarea.text = "I detect the event"; } ]]> </mx:Script> <mx:TextArea id="showarea" x="112" y="124" /> <mx:Button id="eventButton" click="btnclick()" label="DisPatchEvent" /> </mx:TitleWindow> Event class package Events { import flash.events.Event; public class MyEvent extends Event { public static const TestEvent:String = "This is a test event"; public function MyEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=false) { super(type, bubbles, cancelable); } } } |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise