View-View Event Processing

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default View-View Event Processing

    I am not getting View to View Event processing to work. I have looked through
    most of the Flex 2 and Flex 3 docs plus several of the Flex books to try to get
    this to work. I am only trying to get one view to create an event with
    additional information, pass it to another view which intercepts and then uses
    the event information. My simple exploratory code is:

    VIEW1 - Initiating view:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
    creationComplete="init()">
    <mx:Metadata>
    [Event(name = "monitorChange", type = "events.MonitorEvent")]
    </mx:Metadata>
    <mx:Script>
    <![CDATA[
    import mx.events.*;
    import events.MonitorEvent;
    [Bindable]
    private var test:String = "initial";
    private function init():void
    {this.addEventListener(MonitorEvent.MONITOR_CHANGE , monitorChange);
    test = "add event listener";
    }
    private function monitorChange(event:MonitorEvent):void
    {test = "add monitor event: " + String(event.ct);
    }
    private function startEvent():void
    {var e:MonitorEvent = new MonitorEvent("monitorChange", 5);
    this.dispatchEvent(e);
    }
    private function clearLabel():void
    {test = "clear listener";
    }
    ]]>
    </mx:Script>
    <mx:Button label="Event" left="300" top="8" click="startEvent()"/>
    <mx:Button label="Clear" left="380" top="8" click="clearLabel()"/>
    <mx:Label text="{test}" left="700" top="8"/>
    </mx:Canvas>

    VIEW2 ? receiving view:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
    <mx:Script>
    <![CDATA[
    import mx.events.*;
    import events.MonitorEvent;

    [Bindable]
    private var test:String = "initial";

    private function init():void
    {this.eventTest.addEventListener(MonitorEvent.MONI TOR_CHANGE, monitorChange);
    test = "add event listener";
    }
    private function monitorChange(event:MonitorEvent):void
    {test = "add monitor event";
    }
    ]]>
    </mx:Script>
    <mx:Label id="eventTest" text="{test}" left="700" top="8"/>
    </mx:Canvas>

    CUSTOM EVENT:

    package events
    {import flash.events.Event;
    public class MonitorEvent extends Event
    {
    public function MonitorEvent(type:String, ct:int=0)
    {super(type);
    this.ct = ct;
    }
    public static const MONITOR_CHANGE:String = "monitorChange";
    public var ct:int;

    override public function clone():Event
    {return new MonitorEvent(type, ct);
    }
    }
    }

    The event is started in VIEW1 and processed but is not picked up in VIEW2. I
    can see that the listener in VIEW2 is loaded but nothing happens in VIEW2 when
    started in VIEW1. I am sure I am doing something stupid or not seeing the
    obvious. I would greatly appreciate help in getting this to work since this
    seems like the most straight forward way to pass information between
    asynchronous events within an application and keep everything sync?ed.


    Brent Wientjes Guest

  2. Similar Questions and Discussions

    1. DW Split View - Design View
      When working in DW in Split View, when the user clicks into the Design View window the view automatically updates the view if code view has changed....
    2. Event view in windows server 2000
      I tried to find the windows 2000 server section, but obviously it is being made obsolete. I am running windows 2000 server and when I check the...
    3. Standard View vs. Layout View
      view>table view joe "lilyeq" <webforumsuser@macromedia.com> wrote in message news:bfm6gt$qla$1@forums.macromedia.com... making tables. In...
    4. Code view & Layout view
      Hello all, I have a problem! I have a .htm document where I can see the code view, but I can't see anything in the Layout view. Only the tables....
    5. Wierd error when going to Design View from HTML view
      When I go from HTML view (in a webform) to Design View I get the following error: Could not open in Design view. Quote values differently inside a...
  3. #2

    Default Re: View-View Event Processing

    I think I have figured out the missing piece. As the event bubbles up from the
    original view, it only goes up the application tree. It does not take any of
    the branches off the tree. The 2 views were on parallel branches and thus the
    2nd view never responded to the event. The solution is have a listener respond
    to the event above the 1st view that will initiate action in the 2nd view. In
    my case the parent of VIEW1 and VIEW2 are the same. Have parent listen to
    VIEW1 event and respond by calling appropriate routine in VIEW2.

    Simple concept but I missed it in all the reading.

    Brent Wientjes Guest

Posting Permissions

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

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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139