Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 4 of 4

Thread: dispatching event on behalf of non display objects

  1. #1

    dispatching event on behalf of non display objects

    This happens to be a really difficult question to ask. And maybe the answer is terribly simple and I have simply overlooked it. Happens all the time. Anyway.....

    Say you have a non-visual class (one that does not reside on the display list). This custom class, thru composition, will have a property that is a visual class that DOES reside on the display list. This custom class will also implement IEventDispatcher. So how do I do this:

    public class MyNonVizClass implements IEventDispatcher
    private var vizProperty:IEventDispatcher;
    public function MyNonVizClass ()
       //instead of this
       vizProperty = new EventDispatcher(this);
       //I want to do this
       vizProperty = new Sprite(this);
    Basically I want to be able to dispatch the event from the custom class and have the event.target still reference the class rather than the IEventDispatcher property contained within.

    I know this is possible somehow because I think Papervision3D implements something like this. Sadly I havne't been able to find the code in their codebase. I have a work around called an EventDispatcherProxy but it lacks finesse.
    email: jwopitz (at) gmail (dot) com
    blogs: http://jwopitz.wordpress.com
    check out the as3isolib

  2. #2
    if Sprite dispatches an event, its target will always be that sprite. The only way to change that is to re-dispatch the event through your own object, or an EventDispatcher targeting your object (new EventDispatcher(this)). If you need the sprite events to be your class instance's, then you'll have to capture them from the sprite, and re-dispatch them through your class. Your EventDispatcherProxy can probably handle this pretty well, though a more straightforward way would be to addEventListener with the listener being vizProperty.dispatchEvent (where vizProperty is the EventDispatcher).

  3. #3

    seamless my Event non display objects (or any object)

    package lex{
     import flash.events.Event;
     public class LexEvent extends Event {
      //public static const OBJ_SELECT:String = "objSelect";
      public static const SIM_BTN_CLICK:String = "simBtnClick";
      public var params:Object;
      public function LexEvent(_type:String, _params:Object, _bubbles:Boolean = false, _cancelable:Boolean = false ) {
       super( _type, _bubbles, _cancelable );
       this.params = _params;
      public override function toString():String {
       return formatToString("CustomEvent","params","type","bubbles","cancelable");
      public override function clone():Event{
       return new LexEvent(type, params, bubbles, cancelable);
    package lex{
     import flash.events.*;
     public class LexDisp extends EventDispatcher {
      public var obj:Object;
      public function LexDisp(_obj:Object) {
       obj = _obj;
    first frame
    import lex.*;
    var o:Object = {xm:"XM"};
    var disp:LexDisp = new LexDisp(o);
    var e:LexEvent = new LexEvent("hello",{str:"pricolo"});
    function helloEventHandler(e:LexEvent):void{
    I feel good.

  4. #4
    @alex lexcuk
    sorry but I didn't quite get this.

    Thanks Senocular. I was afraid that was the answer. But since I hadn't ever played with the Object.prototype or Object.constructor properties before I wasn't sure if there was a trick to this. I guess yeah for now the EventDispatcherProxy class I have written will suffice.

    Alot of 3D SDKs/APIs out there utilize this concept of having a pure data object make reference to the visual object on screen. When needing to tie into the display list, the data object utilizes the visual object, and that visual object dispatches events on behalf of the "owner", in this case the data object. So maybe Adobe will listen if I mention that we need a tie-in property so that we can dispatch events on behalf of other objects, where the dispatching object is more complex than a simple EventDispatcher.

    public interface IEventDispatcherProxy
    function get eventDispatcherTarget ():IEventDispatcher;
    function set eventDispatcherTarget (value:IEventDispatcher):void;
    then an implementation would be something kinda like so:
    //assuming all DisplayObject classes implemented EventDispatcherProxy
    var proxy:IEventDispatcherProxy = new Sprite();
    var proxyTarget:IEventDispatcher = new NonVisualClass(proxy);
    //constructor would hook up IEventDispatcher mechanisms
    proxy.eventDispatcherTarget = proxyTarget;
    proxyTarget.dispatchEvent(new Event("customEvent", true));
    trace(evt.target); //would trace proxyTarget even tho the Sprite was the actual dispatcher of the event.
    I dunno but I think that having a built in API rather than hack like mine would be great for certain unique situations.
    email: jwopitz (at) gmail (dot) com
    blogs: http://jwopitz.wordpress.com
    check out the as3isolib

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012