Ask a Question related to Macromedia Flex General Discussion, Design and Development.
-
Brent Wientjes #1
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
-
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.... -
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... -
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... -
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.... -
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... -
Brent Wientjes #2
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



Reply With Quote

