Custom Event Bubble
I'm new to flex and how it handles Event Bubbling. I can make a custom event work with this code:
<?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="955" minHeight="600"
applicationComplete="init()" name="app">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.events.Event;
import mx.controls.Alert;
private function init():void {
addEventListener("myEvent",testListener);
var testEvent:Event = new Event("myEvent",true);
dispatchEvent(testEvent);
private function testListener(event:Event):void {
Alert.show("Trigger Worked");
]]>
</fx:Script>
</s:Application>
But when I break out the code so the Event fires in a class the parent does not catch it.
MyEvent.as file:
package comp {
import flash.display.MovieClip;
import flash.events.Event;
public class MyEvent extends MovieClip{
public function MyEvent() {
var testEvent:Event = new Event("myEvent",true);
dispatchEvent(testEvent);
TestEvents.mxml file:
<?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="955" minHeight="600"
applicationComplete="init()" name="app">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import comp.MyEvent;
import flash.events.Event;
import mx.controls.Alert;
private function init():void {
addEventListener("myEvent",testListener);
var tempEvent:MyEvent = new MyEvent();
private function testListener(event:Event):void {
Alert.show("Trigger Worked");
]]>
</fx:Script>
</s:Application>
I know I'm missing something simple. Could someone please point me in the correct direction.
Thanks,
Sol
Thanks for the help!!! I got it to work using most of your code. The only change I had to make was move the dispatchEvent out of the construtor and into it's own function. That way the listener is definded before it fires.
Now I noticed you added the listener to the object itself is this bubbling? I thought if you have bubbling turned on the main app can have the listener and if a child fires an event it would bubble up. If the listerner is not on the MyEvent class it does not work.
Here is the new Working code if you take the : tempMyEvent off this line:
addEventListener(MyEvent.MY_EVENT, myEventHandler);
it does not work
Should it? Should the event bubble up and still be fired?
Below is working code:
MyEvent.as
package comp {
import flash.display.MovieClip;
import flash.events.Event;
public class MyEvent extends MovieClip{
public static const MY_EVENT:String = 'myEvent';
public function MyEvent() {}
public function disEventTest():void {
dispatchEvent(new Event(MyEvent.MY_EVENT,true));
TestEvents.mxml
<?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="955" minHeight="600"
applicationComplete="init()" name="app">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import comp.MyEvent;
import flash.events.Event;
import mx.controls.Alert;
private function init():void {
var tempMyEvent:MyEvent = new MyEvent();
tempMyEvent.addEventListener(MyEvent.MY_EVENT, myEventHandler);
tempMyEvent.disEventTest();
private function myEventHandler(event:Event):void {
Alert.show("Trigger Worked");
]]>
</fx:Script>
</s:Application>
Thanks again for your help this will at least get me moving forward again.
Sol
Similar Messages
-
Event Bubbling Custom Object not inheriting from control
One of the new things flash flex and xaml have are ways which
the event easily bubbles up to a parent that knows how to handle
the event. Similar to exceptions travel up until someone catches
it.
My goal is to use the frameworks event system on custom
objects. My custom objects are:
ApplicationConfiguration
through composition contains:
SecurityCollection which contains many or no SecurityElements
and
FileSystemCollection.cs which contains many or no
FileSystemElement objects
ect ect basically defining the following xml file with custom
objects.
[code]
<ApplicationConfiguration>
<communication>
<hardwareinterface type="Ethernet">
<ethernet localipaddress="192.168.1.2" localport="5555"
remoteipaddress="192.168.1.1" remoteport="5555" />
<serial baudrate="115200" port="COM1" />
</hardwareinterface>
<timing type="InternalClock" />
</communication>
<filesystem>
<add id="location.scriptfiles" value="c:\\" />
<add id="location.logfiles" value="c:\\" />
<add id="location.configurationfiles" value="c:\\" />
</filesystem>
<security>
<add id="name1" value="secret1" />
<add id="name2" value="secret2" />
</security>
<logging EnableLogging="true"
LogApplicationExceptions="true" LogInvalidMessages="true"
CreateTranscript="true" />
</ApplicationConfiguration>
[/code]
basically these custom objects abstract the xml details of
accessing attributes, writing content out of the higher application
layers.
These custom objects hold the application configuration which
contains the users options. The gui application uses these
parameters across various windows forms, modal dialog boxes ect.
The gui has a modal dialog that allows the user to modify these
parameters during runtime.
basically i manage: load, store, new, edit, delete of these
configuration files using my custom objects.
Where would event propagation help in custom objects like
described above?
ConfigurationSingleton.getInstance().ApplicationConfiguration.CommunicationElement.Hardwar eInterfaceElement.EthernetElement.RemoteIPAddress
=
System.Net.IPAddress.Parse(this.textBoxRemoteEthernetIpAddress.Text);
The EthernetElement should propagate a changed event up to
the parent ApplicationConfiguration which would persist this to the
registry, db, file or whatever backend.
currently this logic is maintained else where. I serialize
the root node which compositely serializing the nested nodes and i
check of the serialization is different from that in the backend
… This tells me if the dom was modified. It works but i would
like an event driven system.
how should i implement bubbling using custom objects?
3 implementation ideas:
1) A simple way is to implement a singleton event manager:
EventManager.RegisterRoutedEvent
http://msdn2.microsoft.com/en-us/library/ms742806.aspx
I like this idea but how can you tell which object is nested
in who… this way the event can be stopped and discontinue
propagation?
2) If i use binders as discussed in Apress’s book:
Event-Based
Programming Taking Events to the Limit
basically a binder connects the events between seperate
objects together… although it would work for my app, I would
like a more generalized approach so i can reuse the event system on
future project.
3) how does flash flex handle this..
objectproxy.as?
http://www.gamejd.com/resource/apollo_alpha1_docs/apiReference/combined/mx/utils/ObjectPro xy.html#getComplexProperty()
>Provides a place for subclasses to override how a complex
property that needs to be either proxied or daisy chained for event
bubbling is managed.
how does these systems all work....? Reflection ?
this way i can simulate this on my own custom classes.
Thanks!I have a strong sensation that the OSMF project is quite dead.
no new submits since 2010, the contact form on the offical OSMF
project website http://www.opensourcemediaframework.com/
returns a PHP error.
and many unanswered questions about OSMF in this forum.
i think it would be wise to not use OSMF if possible, although
I'm also stuck with it since we are utilizing HDS/PHDS
protocols which are utilized in the framework.
otherwise its quite a head-ache.
I'm unable to get to a video element coming from a proxied element
that is being produced via an HDS connection.
and haven't found any solution that works. -
Event Bubbling from inside a MediaElement
Hi,
Does anyone know how to bubble a custom event from inside a ProxyElement? My ProxyElement wraps the target media inside a SerialElement and prepends a clip. I'm wondering how to dispatch an event which I could capture outside of OSMF (bubbles all the way up to Stage).
I've tried dispatching from the ProxyElement, the SerialElement it creates, the VideoElement inside the serialElement, and also from the DisplayObjectTrait of each of those. I'm unable to successfully capture it via bubbling.
In contrast I've modified the AdProxy example (org.osmf.examples.ads.AdProxy) and I can successfully capture a bubbled event dispatched via the displayObject it creates. I believe this may be due to its use of a custom AdProxyDisplayObjectTrait? It doesn't seem to do anything fancy so I'm not sure why it works yet my other attemps don't.
Speaking of the AdProxy example. If i modify it to create a SerialElement and prepend a clip only the first clip plays correctly, all subseqwuent clips are heard but not seen. Is this a bug or do I need to somehow remove the custom AdProxyDisplayObjectTrait to resolve this issue? The child media claims it correctly has its own DisplayObjectTrait and the dimensions are correct. I'm using OSMF 1.6.1.
Cheers,
TimI have a strong sensation that the OSMF project is quite dead.
no new submits since 2010, the contact form on the offical OSMF
project website http://www.opensourcemediaframework.com/
returns a PHP error.
and many unanswered questions about OSMF in this forum.
i think it would be wise to not use OSMF if possible, although
I'm also stuck with it since we are utilizing HDS/PHDS
protocols which are utilized in the framework.
otherwise its quite a head-ache.
I'm unable to get to a video element coming from a proxied element
that is being produced via an HDS connection.
and haven't found any solution that works. -
Reverse event bubbling/dropping
Hi!
I use custom components to organize my application. Event
bubbling from a nested component to the application works fine. Is
it also possible to notify any component tested in the application
with an event triggered by the appplication or another component at
the same level?
THXComponents have to listen/register to receive events, either
during the capture or bubble phase. So a child component can listen
for a component by its using parent.addEventListener( "eventname",
eventHandlerFunction ); -
Eventhandlers of children of application can not receive custom event dispatched by application
Hello dear Adobe community,
hope you can help me with this issue.
When the application dispatches a custom event, the child uicomponent can only receive the event by using Application.application.addEventListener or systemManager.addEventListener. Simply adding a listener, without application or systemmanager, does not allow the event to be received by the child component.
I want to be able to use the addEventListener and removeEventListener without SystemManager or Application.application, or could you provide a better workaround? How can I use the addEventListener, do I need to overwrite EventDispatcher, which I wouldnt like to do?
Just to clarifiy, if i remove the systemManager in front of addEventListener(CustomEventOne.EventOne,sysManHandleCE,false) it will not add it and will not fire.
The code below is an example for this problem that the event is not getting fired in the right moment. The mainapplication got only a button with the customEventOne that gets dispatched.
public
class MyCanvas extends Canvas{
public function MyCanvas()
super();
width=300;
height=300;
addEventListener(FlexEvent.CREATION_COMPLETE,handleCC,false,0,true);
private function handleCC(event:FlexEvent):void
removeEventListener(FlexEvent.CREATION_COMPLETE,handleCC);
addEventListener(CustomEventOne.EventOne,handleCE,false,0,true);
addEventListener(Event.REMOVED_FROM_STAGE,handleEvt,false,0,true);
systemManager.addeventListener(CustomEventOne.eventOne,sysManHandleCE,false,0,true);
private function handleEvt(event:Event):void
trace("In removed from stage handler");
systemManager.removeEventListener(CustomEventOne.EventOne,sysManHandleCE);
trace(hasEventListener(FlexEvent.CREATION_COMPLETE));
trace(hasEventListener(CustomEventOne.EventOne));
trace(hasEventListener(Event.REMOVED_FROM_STAGE));
private function handleCE(event:CustomEventOne):void
trace("I got it");
private function sysManHandleCE(event:CustomEventOne):void
trace("I got it");
public class CustomEventOne extends Event
public static const EventOne:String = "EventOne";
public function CustomEventOne(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
super(type, bubbles, cancelable);
override public functionclone():Event
return newCustomEventOne(type,bubbles,cancelable);
Thank you in advance,
MichaelI think you need to look at event propogation. The object that dispatches an event will be sitting on the display tree. The event propagates up the tree to the roots. Your canvas should be attached to the application, but even then it sits lower in the tree branches than the event dispatcher, so it won't see the event being dispatched because the event is not propagated to the children of the object that dispatches it but to the parent of the object that dispatches it.
So, your canvas is a child of the application, but dispatching the event from the application means that the canvas doesn't see it because events are notified up the tree using the parent link, not the child links.
You may wish to investigate how the display list and event propagation works and then the MVC pattern.
Paul -
Hope you flex geniuses can help me on this one....
the issue: an action script custom event is being dispatched
by one object but is not being "heard" by it's parent despite the
fact that a) the child object uses the [event] declaration in it's
class definition, b) the event is being correctly dispatched, and
c) the parent object uses an addEventListener method to listen for
the event.
the layout:
includes an application component (mxml) that has as it's
only direct child an action script custom component called
FloorPlan. On creationComplete the floor plan object instantiates
an action script class called Booth as many times as is required
(based on the number of booths that needs to be displayed on the
floor plan) and then adds the instances to itself via addChild()
method. The booth objects are based on Sprite class and so they
have click events, etc. When one of the booth instances is clicked,
the click event of the booth instance fires and the handler creates
an instance of the ShowCompanyProfileEvent (action script class
based on the Event class) and then dispatches it. The
ShowCompanyProfileEvent event handler for now should just open an
Alert box.
I know the code works within the Booth class because when I
register an event listener in the booth class itself and then click
on a booth, the listener "hears" the dispatched event and opens the
Alert box.
The problem is that The floor plan instance has a registered
event listener to listen for the dispatched custom event also but
nothing happens when I click a booth instance (which like I said
should dispatch the custom event). I deleted the addEventListener
code in the booth class thinking that maybe it was catching it
first but still it wouldn't work.
Any ideas? I have reallysearched and searched to no avail. As
I mentioned, I get no errors at all when I compile and run the
code. I just don't get the expected results.LensterRAD, don't know if I got the hole idea but I guess you
are listening to the ShowCompanyProfileEvent directly on the
FloorPlan, something like:
FloorPlan.addEventListener(ShowCompanyProfileEvent,
someFunction);
if this is the case, you'll probably need to add the BUBBLE
parameter to the event, so it will follow the hole event
propagation model.
something like: dispatchEvent(ShowCompanyProfileEvent,
true); -
What is the lifecycle of Event or Custom Event
Hi All,
Can anybody please let me know the life cycle of event or custom event and what exactly is event bubbling.
Thankshi 194642537,
http://ted.onflash.org/2007/02/flex-instantiation-life-cycle-and-event.php , http://www.slideshare.net/mohamedkamil/adobe-component-life-cycle
just try with this links.. it ll may help u.. -
Passing custom events between modules through parent application
I have created a custom event that I want to use to pass a string between two modules. The event looks like this:
package com.mypackage.events
import flash.events.Event;
public class ThumbDeleteEvent extends Event
public static const THUMBS_DELETED:String = "thumbsDeleted";
public var files:String;
public function ThumbDeleteEvent(type:String, files:String)
super(type);
this.files = files;
// Override the inherited clone() method.
override public function clone():Event {
return new ThumbDeleteEvent(type, files);
In one module I dispatch the event like so:
parentApplication.dispatchEvent(new ThumbDeleteEvent("parentApplication.thumbsDeleted", files));
and in another module I listen for the event like so:
public function init():void {
parentApplication.addEventListener("parentApplication.thumbsDeleted", onThumbsDelete);
if I use ThumbsDeleteEvent as the type passed in to the listener function like this:
public function onThumbsDelete(evt:ThumbDeleteEvent):void{
trace("thumb delete event for thumbs: "+evt.files);
I get the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert com.mypackage.events::ThumbDeleteEvent@26748a31 to com.mypackage.events.ThumbDeleteEvent.
if I just use Event as the type passed in to the listener function like this:
public function onThumbsDelete(evt:ThumbDeleteEvent):void{
if(evt is ThumbDeleteEvent){
trace("thumb delete event for thumbs: "+(evt as ThumbDeleteEvent).files);
}else{
var type:XML = describeType(evt);
trace(type.toXMLString());
It works but does not think it is a ThumbDeleteEvent type class (it hits the else statement) the xml output of describe type says its type is:
type name="com.mypackage.events::ThumbDeleteEvent"
What is going on here? If I put a breakpoint in the debugger it says the event is a ThumbDeleteEvent and I can see the files parameter and its right???Sorry I have been trying all sorts of stuff and I cut and pasted the wrong version, I meant to put this:
if I just use Event as the type passed in to the listener function like this:
public function onThumbsDelete(evt:Event):void{
if(evt is ThumbDeleteEvent){
trace("thumb delete event for thumbs: "+(evt as ThumbDeleteEvent).files);
}else{
var type:XML = describeType(evt);
trace(type.toXMLString());
Then it gets passed to the else condition (it does not recognize it as a ThumbDeleteEvent) and this is the output of the trace:
<type name="com.helius.events::ThumbDeleteEvent" base="flash.events::Event" isDynamic="false" isFinal="false" isStatic="false">
<extendsClass type="flash.events::Event"/>
<extendsClass type="Object"/>
<constructor>
<parameter index="1" type="String" optional="false"/>
<parameter index="2" type="String" optional="false"/>
<parameter index="3" type="Boolean" optional="true"/>
<parameter index="4" type="Boolean" optional="true"/>
</constructor>
<variable name="files" type="String"/>
<accessor name="type" access="readonly" type="String" declaredBy="flash.events::Event"/>
<accessor name="bubbles" access="readonly" type="Boolean" declaredBy="flash.events::Event"/>
<accessor name="cancelable" access="readonly" type="Boolean" declaredBy="flash.events::Event"/>
<accessor name="target" access="readonly" type="Object" declaredBy="flash.events::Event"/>
<accessor name="currentTarget" access="readonly" type="Object" declaredBy="flash.events::Event"/>
<accessor name="eventPhase" access="readonly" type="uint" declaredBy="flash.events::Event"/>
<method name="stopImmediatePropagation" declaredBy="flash.events::Event" returnType="void"/>
<method name="preventDefault" declaredBy="flash.events::Event" returnType="void"/>
<method name="isDefaultPrevented" declaredBy="flash.events::Event" returnType="Boolean"/>
<method name="clone" declaredBy="com.helius.events::ThumbDeleteEvent" returnType="flash.events::Event"/>
<method name="toString" declaredBy="flash.events::Event" returnType="String"/>
<method name="formatToString" declaredBy="flash.events::Event" returnType="String">
<parameter index="1" type="String" optional="false"/>
</method>
<method name="stopPropagation" declaredBy="flash.events::Event" returnType="void"/>
</type>
This causes a TypeError:
public function onThumbsDelete(evt:ThumbDeleteEvent)
This causes a null pointer error because myevent is null:
public function onThumbsDelete(evt:Event):void{
var myevent:TumbDeleteEvent = (evt as ThumbDeleteEvent);
var files:String = myevent.files;
Here is what I see when I put a break point in and debug it:
I tried upgrading my event extender as you suggested, that had no effect. I removed the dot notation in the type and it does the exact same thing I.E. dispatching class:
parentApplication.dispatchEvent(new ThumbDeleteEvent("thumbsDeleted", files)); or
parentApplication.dispatchEvent(new ThumbDeleteEvent(ThumbDeleteEvent.THUMBS_DELETED, files));
and receiving class:
parentApplication.addEventListener("thumbsDeleted", onThumbsDelete);
I really appreciate your help, I am baffled by this, I have tried everything I can think of for two days and I am ready to start throwing things. -
Dispatching & listening for custom events from custom component [Flex 4.1]
I'm giving this a try for the first time and I'm not sure I have the recipe correct!
I have a custom component - it contains a data grid where I want to double click a row and dispatch an event that a row has been chosen.
I created a custom event
package oss
import flash.events.Event;
public class PersonChosenEvent extends Event
public function PersonChosenEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
super(type, bubbles, cancelable);
// Define static constant.
public static const PERSON_CHOSEN:String = "personChosen";
// Define a public variable to hold the state of the enable property.
public var isEnabled:Boolean;
// Override the inherited clone() method.
override public function clone():Event {
return new PersonChosenEvent(type);
Then I try to dispatch the event within the component when the datagrid is doubleclicked:
import oss.PersonChosenEvent
dispatchEvent(new PersonChosenEvent(PersonChosenEvent.PERSON_CHOSEN, true, false));
And in the parent application containing the component I do on creationComplete
addEventListener(PersonChosenEvent.PERSON_CHOSEN,addPersonToList);
The event does not seem to fire though. And if I try to evaluate the "new PersonChosenEvent(..." code it tells me "no such variable".
What am I doing wrong?
(It was so easy in VisualAge for Java, what have we done in the last 10 years?? )
MartinI've done this kind of thing routinely, when I want to add information to the event. I never code the "clone" method at all.
Be sure that you are listening to the event on a parent of the dispatching component.
You can also have the dispatching component listen for the event too, and use trace() to get a debug message.
I doubt if it has anything to to with "bubbles" since the default is true.
Sample code
In a child (BorderContainer)
dispatchEvent(new ActivationEvent(ActivationEvent.CREATION_COMPLETE,null,window));
In the container parent (BorderContainer)
activation.addEventListener(ActivationEvent.CREATION_COMPLETE,activationEvent);
package components.events
import components.containers.SemanticWindow;
import components.triples.SemanticActivation;
import flash.events.Event;
public class ActivationEvent extends Event
public static const LOADED:String = "ActivationEvent: loaded";
public static const CREATION_COMPLETE:String = "ActivationEvent: creation complete";
public static const RELOADED:String = "ActivationEvent: reloaded";
public static const LEFT_SIDE:String = "ActivationEvent: left side";
public static const RIGHT_SIDE:String = "ActivationEvent: right side";
private var _activation:SemanticActivation;
private var _window:SemanticWindow;
public function ActivationEvent(type:String, activation:SemanticActivation, window:SemanticWindow)
super(type);
_activation = activation;
_window = window
public function get activation():SemanticActivation {
return _activation;
public function get window():SemanticWindow{
return _window; -
Custom Event and Custom itemRenderer
I created an MXML component based on <mx:Button/> and
am using it as a custom itemRenderer in a DataGrid.
I also created a custom event, and my custom itemRenderer
dispatches the event. I know the event gets dispatched because I
see it in the debugger.
I register an event listener in the parent of the DataGrid,
but the event handler is not being called.
If you have any advice, please help.In the DeleteItemEvent constructor:
super(type, bubbles);
TS -
How to dispatch custom events from an item renderer used for Datagrid Column
Hi,
I am using an Item Renderer for a Data Grid Column and in that mxml, I am dispatching a custom event with data.
But the main mxml which has the DataGrid is not able to resolve the event. How can I solve this?
ThanksHi,
This is the constructor for Event.
public function Event(type:String, bubbles:Boolean = false, cancelable:Boolean = false)
When you created your custom event after extending from Event, for the parent container receives the event, the bubbles property must be set to true.
Please check if you have done so. That should solve the problem. Let me know if it doesn't.
Nishad -
How to acknowledge custom event?
Helllo All
I did a custom event class, imported it in main application,
added event metatags in it, and dispatched this event along with my
custom data !
Works fine till above point
now my question is
how can i acknowledge that event in a nested component?
Main Application - TileList Component - [Item renderer
Component]
Thanks in advanceHi,
Try setting the bubbles property of your custom event to true
and then register a listener for the custom event on the parent of
the component.
Hope this helps. -
Custom Event with multiple EventTypes
Hello All, First thanks for all those who tryied to help me and apologize for my approximative english.
I would like to create the more properly as possible a Custom Event with multiple EventTypes, like the MouseEvent typicaly.
With Some EventType which permit to acces to some attributes and other not. But I'm totaly lost, The second solution if someone knows how, is to explain to me how to do to acces to the code of the MouseEvent.as
Thanks!
Ps: you will find below the basis of the code i have begin.
package fr.flashProject
import flash.events.Event;
* @author
public class SWFAddressManagerEvent extends Event
public static const CHANGE_PAGE:String = "change_page";
public static const ERROR_404:String = "error_404";
public static const HOME_PAGE:String = "home_page";
private var _page:String;
private var _params:Object;
public function SWFAddressManagerEvent(type:String, pPage:String = null, pParams:Object = null, bubbles:Boolean=false, cancelable:Boolean=false)
super(type, bubbles, cancelable);
_page = pPage;
_params = _params;
public override function clone():Event
return new SWFAddressManagerEvent(_type, _page, _params, bubbles, cancelable);
public override function toString():String
return formatToString("SWFAddressManagerEvent", "type", "page", "params", "bubbles", "cancelable", "eventPhase");
public function get page():String { return _page; }
public function get params():Object { return _params; }I am not sure what you are trying to accomplish but event can have only single type. Event type is just a string that is typically a constant - exactly like your constants.
When dispatched, each event INSTANCE has only one type. Again, these types are described in a type parameter by a string. Each dispatched MouseEvent DOES NOT have multiple types but ONLY ONE. It does have multiple constants that are used to assign type at runtime as does your event.
If you are talking about multiple parameters, you already do that in your custom event class. You have _page and _params. Nothing stops you from adding more parameters.
Also I am not sure why you need getters for _page and _params. -
My New Flex Cookbook Post on Using Custom Events
I just created a Flex Cookbook post on using custom events to pass data between the Flex application and custom components:
http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postI d=15466&loc=en_US
Hope it helps.After perusing the SDK classes, I realize that all arguments from the superclass should go first in constructor arguments.
Also, although we are listening in capture phase, both the bubble and capture phase have the problem of requiring unique event names. This is why the application frameworks recommend singletons like model singletons so you can listen directly to them instead of basically broadcasting to everyone (bubbling) or listening to everyone (capture).
That would be a bit more complex, and I am trying to keep this simple, but another good point to keep in mind. -
Hi all,
Is there any chance I can propagate custom events in ScriptUI ? I tried this sample in ESTK and it works fine. However I tried to run it in several CS apps and all my attempts raised errors. My intenttion is to create custom components that would throw events listened by the parent window. Am I asking too much ?
function test()
var w = new Window('dialog');
var btn = w.add('button');
w.addEventListener ('custom', tata);
btn.onClick = function()
w.close()
var e = new UIEvent('custom', true, true, w, null);
e.data= {test:"hello"};
w.dispatchEvent(e)
function tata(e)
alert(e.data.test);
w.show();
test();
Thanks for any hint/advice,
LoicHi Loïc,
To my knowledge new UIEvent(…) works fine in InDesign (CS4/CS5/CS6) provided that you let the view parameter undefined.
So just try to replace:
var e = new UIEvent('custom', true, true, w, null);
by:
var e = new UIEvent('custom', true, true);
Note: Usually a custom UI event should be dispatched from a specific target—in your case: btn.dispatchEvent(e)—rather than from the top window. This way you can have multiple listeners that the event will hit during the bubbling phase:
// Propagation of a custom UI event (which bubbles)
// Tested in ID CS4/CS5/CS6
const EV_TYPE = 'MyCustomEventType';
var u,
w = new Window('dialog'),
p = w.add('panel'),
b = p.add('button',u,"Test"),
evHandler = function(ev)
alert( this + " is listening: " + ev.data );
myDispatcher = function(data)
var ev = new UIEvent(EV_TYPE, true, true);
ev.data = data;
this.dispatchEvent(ev);
w.addEventListener(EV_TYPE, evHandler);
p.addEventListener(EV_TYPE, evHandler);
b.onClick = function(){ myDispatcher.call(this, "Some data"); }
w.show();
@+
Marc
Maybe you are looking for
-
Using Webservices in the Self Service UI
WHat is the best practice to show new fields in Self Service UI pages with out changing existing UI elements? We created new proxies for Siebel WSDL and want to show new fields in the UI. We don't want to create new view object and link with AM to sh
-
I've just wrote a plug-in which extends Ilustrator 's file types reading and writing. As a File Format plug-in, the main entry point of this plugin is an the "format" item added in the save dialog box. The problem is that, we want me to do that in a
-
TimeFormat() statement that worked now fails
I've been using the statement below to create a date/time string like "2007-10-17T11:26:01Z". <cfset strDateTime = DateFormat(Now(), "YYYY-MM-DD") & "T" & TimeFormat(Now(), "HH:mm:ssZ")> This has always worked correctly but suddenly on one of our pro
-
Unable to update my payment information
HI, One of my transaction failed on the ITUNES STORE as it has stopped acepting virtual credit cards in india. After that when i added a real credit card to the edit payment info page, it simply displays a message that Contact iTunes support for this
-
Quick searching by multiple keywords
Hi, Just a quick question. I don't seem to be able to search for multiple keywords through the quicksearch input (on the top right of the browser window). If I put in one keyword it works like a charm, but if I enter two (with either spaces or commas