tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/1172-how-can-i-get-exact-view-position-from-an-another-meditator-classRobotlegs: Discussion 2012-10-24T08:35:18Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/199552862012-10-24T07:30:52Z2012-10-24T07:30:52ZHow can i get exact view position from an another meditator class?<div><p>Hi Ahmet,</p>
<p>Views can communicate with each other through their Mediators
via custom events.<br>
In the example below, SomeView dispatches SomeLayoutEvent and its
SomeViewMediator redispatches the event on the shared event
dispatcher. AnotherMediator listens for the event and accesses a
method on its view, passing on the payload of the event.<br>
The payload can be anything you need it to be (Array, Point,
VO).</p>
<p>SomeLayoutEvent:</p>
<pre>
<code>public static const VIEW_POSITION_CHANGED:String="viewPositionChanged";
public function SomeLayoutEvent (type:String, position:Point, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
_position=position;
}
override public function clone():Event
{
return new SomeLayoutEvent (type, position, bubbles, cancelable);
}
public function get position():Point
{
return _position;
}</code>
</pre>
<p>SomeView:</p>
<pre>
<code>var viewPosition:Point=new Point(this.x, this.y);
dispatchEvent(new SomeLayoutEvent(SomeLayoutEvent.VIEW_POSITION_CHANGED, viewPosition));</code>
</pre>
<p>SomeViewMediator:</p>
<pre>
<code>override public function onRegister():void
{
eventMap.mapListener(view, SomeLayoutEvent.VIEW_POSITION_CHANGED, dispatch, SomeLayoutEvent);
}</code>
</pre>
<p>AnotherViewMediator:</p>
<pre>
<code>override public function onRegister():void
{
eventMap.mapListener(eventDispatcher, SomeLayoutEvent.VIEW_POSITION_CHANGED, onViewPositionChanged, SomeLayoutEvent);
}
private function onViewPositionChanged(event:SomeLayoutEvent):void
{
view.changeViewPosition(event.position);
}</code>
</pre>
<p>AnotherView:</p>
<pre>
<code>public function changeViewPosition(position:Point):void
{
this.x=position.x;
this.y=position.y;
}</code>
</pre>
<p>Does this answer your question?<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199552862012-10-24T08:18:17Z2012-10-24T08:18:18ZHow can i get exact view position from an another meditator class?<div><p>Hello,<br>
Thank you very much!<br>
This solved my problem.</p></div>Ahmet Alsantag:robotlegs.tenderapp.com,2009-10-18:Comment/199552862012-10-24T08:35:17Z2012-10-24T08:35:17ZHow can i get exact view position from an another meditator class?<div><p>You're welcome!</p></div>Ondina D.F.