Multiple instances of views
I have multiple views where I create multiple instances of the view. The issue I am having is that all mediators mapped to this view are responding to this event.
As an example:
I have created 3 different instances of the view TransactionMain which is mapped to TransactionMainMediator.
When I dispatch the event CreateTransactionSend from the view, all 3 instances of the mediator relay this information to the service, so I wind up with 3 records created.
On response from the service, I dispatch another event, letting the mediator/view know that the service transaction is complete. I have created a simple alert to test. In all tests I get 3 alert windows.
I have verified that I have set the event up to be non-bubbling.
Here is a snippet of my code:
Event:
`
package com.etdm.event.transaction
{
import com.etdm.vo.transaction.TransactionMain;
import flash.events.Event;
public class TransactionMainEvent extends Event
{
public static const CREATE_TRANSACTION_SEND:String = "CreateTransactionSend";
public static const CREATE_TRANSACTION_COMPLETE:String = "CreateTransactionComplete";
public var transactionMain:TransactionMain;
public function TransactionMainEvent(type:String, cancelable:Boolean=false, transactionMain:TransactionMain=null)
{
super(type, bubbles, cancelable);
transactionMain = transactionMain
}
public override function clone():Event
{
return new TransactionMainEvent( type, bubbles, cancelable, transactionMain);
}
}
}
`
View Dispatching Function:
`
private function nTest():void
{
var tMain:TransactionMain = new TransactionMain();
tMain.FileNumber = 1001;
var dataEvent:TransactionMainEvent = new TransactionMainEvent(TransactionMainEvent.CREATE_TRANSACTION_SEND,false);
dataEvent.transactionMain = tMain;
dispatchEvent(dataEvent);
}
`
Mediator
`
package com.etdm.mediator.admin.transaction
{
import com.etdm.event.transaction.TransactionMainEvent;
import com.etdm.service.transaction.ITransactionMainService;
import com.etdm.view.admin.transaction.TransactionGeneral;
import org.robotlegs.mvcs.Mediator;
public class TransactionGeneralMediator extends Mediator
{
[Inject]
public var view:TransactionGeneral;
[Inject]
public var transactionMainService:ITransactionMainService;
public function TransactionGeneralMediator()
{
super();
}
override public function onRegister():void
{
eventMap.mapListener(view, TransactionMainEvent.CREATE_TRANSACTION_SEND, OnCreateTransactionSend);
}
private function OnTransactionMainSend(event:TransactionMainEvent):void
{
transactionMainService.CreateTransactionMain(event.transactionMain);
}
}
}
`
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Stray closed this discussion on 02 May, 2011 01:27 PM.