this listener is in the view. The Event extends Event and has the bubbling set
to true by default
View:
public function attemptLogin(username:String, password:String):void {
this.addEventListener(LoginEvent.FAILED, loginFailed);
var login:LoginEvent = new LoginEvent(LoginEvent.LOGIN);
login.username = username;
login.password = password;
dispatchEvent(login);
}
Event:
package com.isavepets.rm.events
{
import flash.events.Event;
public class LoginEvent extends Event
{
public static const LOGIN:String = "loginEvent";
public static const LOGOUT:String = "logoutEvent";
public static const FAILED:String = "loginAttemptFailedEvent";
public var username:String;
public var password:String;
public function LoginEvent(type:String, bubbles:Boolean=true,
cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
}
}
----------------------------------------
From: "Tracy Spratt" <[email protected]>
Sent: Wednesday, September 02, 2009 9:54 PM
To: [email protected]
Subject: RE: [flexcoders] Why no event dispatched?
And I don't see where you are
declaring the listener. Tracy Spratt, Lariat Services, development services
available
----------------------------------------
From: [email protected] [mailto:[email protected]] On Behalf
Of Fotis Chatzinikos
Sent: Tuesday, September 01, 2009
4:11 AM
To:[email protected]
Subject: Re: [flexcoders] Why no
event dispatched?
Do what Tracy
mentions:
either add bubbles=true in the constructor here:
this.dispatchEvent(new LoginEvent(LoginEvent.FAILED))
On Mon, Aug 31, 2009 at 9:40 PM, Wally Kolcz <[email protected]> wrote:
My
Events:
package com.isavepets.rm.events
{
import flash.events.Event;
public class LoginEvent extends Event
{
public static const LOGIN:String =
"loginEvent";
public static const LOGOUT:String =
"logoutEvent";
public static const FAILED:String =
"loginAttemptFailedEvent";
public var username:String;
public var password:String;
public function LoginEvent(type:String,
bubbles:Boolean=true, cancelable:Boolean=false)
{
super(type, bubbles,
cancelable);
}
}
}
My Listener on the LoginPanel component View:
public function attemptLogin(username:String,
password:String):void {
this.addEventListener(LoginEvent.FAILED, loginFailed);
var
login:LoginEvent = new LoginEvent(LoginEvent.LOGIN);
login.username = username;
login.password = password;
dispatchEvent(login);
}
----------------------------------------
From :
"Tracy Spratt" <[email protected]>
Sent: Monday, August 31, 2009
10:37 AM
To: [email protected]
Subject: RE: [flexcoders] Why no
event dispatched?
Your event is not set to
bubble, so you listener must be: myLoginManagerInstance.addEventListener();
Is it? Tracy Spratt, Lariat Services,
development services available
----------------------------------------
From: [email protected]
[mailto:[email protected]]
On Behalf Of Wally Kolcz
Sent: Monday, August 31, 2009
12:09 PM
To:[email protected]
Subject: [flexcoders] Why no event
dispatched? Can anyone tell me what I
am missing from this Class that not dispatch the LoginEvent.FAILED?
package com.isavepets.rm.business
{
import com.isavepets.rm.events.LoginEvent;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import mx.collections.ArrayCollection;
public class LoginManager extends EventDispatcher
{
public var username:String;
public var role:String;
public var rescueID:int;
public function LoginManager(target:IEventDispatcher=null)
{
super(target);
}
public function manageLogin(e:ArrayCollection):Boolean
{
if (e.length !=0){
DataModel.getInstance().username = e.getItemAt(0).username;
DataModel.getInstance().role = e.getItemAt(0).role;
DataModel.getInstance().rescueID = e.getItemAt(0).rescueID;
return true;
}else{
this.dispatchEvent(new LoginEvent(LoginEvent.FAILED));
/*
Alert.show("Incorrect Username and/or Password, Please Try Again",
"Login Failed"); */
return false;
}
}
}
}
--
Fotis Chatzinikos, Ph.D.
Founder,
Phinnovation
[email protected],