Adobe Dreamweaver Forums



Last 10 THreads :         Mail form not working (Last Post : Alan - Replies : 2 - Views : 3 )           »          Re: Removing unused files from the user's ability tosearch (Last Post : Authorgirl - Replies : 2 - Views : 3 )           »          loader onComplete firing, but TextField not disappearing (Last Post : Manno Bult - Replies : 2 - Views : 3 )           »          Flickering backgroundColor when removing a componentfrom displayList using a removedEffect (Last Post : camwest - Replies : 1 - Views : 7 )           »          Assigning a Variable a Null Value (Last Post : Kronin555 - Replies : 3 - Views : 4 )           »          Space between divs (Last Post : zgot66 - Replies : 11 - Views : 12 )           »          CS4 trials expired too early (Last Post : Wodehouse - Replies : 2 - Views : 4 )           »          CSS help centering across all / most browsers (Last Post : Thierry - Replies : 87 - Views : 88 )           »          First time install, need a little help. (Last Post : firstbat - Replies : 1 - Views : 5 )           »          Blend modes do not work (Last Post : pongtoe - Replies : 0 - Views : 1 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags: ,



Reply
  #1 (permalink)  
Old 08-25-2008, 08:13 AM
ZHB_China
 
Posts: n/a
Diggs:
Default program with event

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");
}
}
}



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-29-2008, 10:43 AM
adobenewsbot
 
Posts: n/a
Diggs:
Default Re: program with event

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].
Reply With Quote
  #3 (permalink)  
Old 08-29-2008, 03:18 PM
SujitG
 
Posts: n/a
Diggs:
Default Re: program with event

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);
}

}
}

Reply With Quote


Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 04:51 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk