[flexcoders] Newbie question: Custom Components and Custom Events

2009-05-04 Thread Alan Rother
Hey All,
I'm playing around with a super simple demo Simeon Bateman posted on his
blog 
(http://blog.simb.net/2009/05/01/flex-101-back-to-the-basics/)http://blog.simb.net/2009/05/01/flex-101-back-to-the-basics/

It's just a little tool designed to teach basic MVC / OO principles to newbs
like me. I've get what it's doing and why it works, now I'm trying to extend
on it.


I'm trying to take this custom component and instead of displaying it in the
main app, open it in a pop up window.

view:UserForm userSubmit=onSubmit(event)/


 I can get it to do that just fine, but I cannot get the custom event
registered with the addEventListener. I get the following error message:

1119: Access of possibly undefined property USER_SUBMIT through a reference
with static type Class.



Any thoughts? It works properly when I use it as is in MXML form, but not
when I try to create the object using AS.


private function openWindow():void {
win = view.UserForm(PopUpManager.createPopUp(this, UserForm, false));
PopUpManager.centerPopUp(win);
win.addEventListener(UserEvents.USER_SUBMIT, onSubmit);
}

-- 
Alan Rother
Adobe Certified Advanced ColdFusion MX 7 Developer
Manager, Phoenix Cold Fusion User Group, AZCFUG.org


RE: [flexcoders] Newbie question: Custom Components and Custom Events

2009-05-04 Thread Tracy Spratt
Did you import UserEvents?

 

Tracy Spratt,

Lariat Services, development services available

  _  

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of Alan Rother
Sent: Monday, May 04, 2009 6:18 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Newbie question: Custom Components and Custom Events

 






Hey All,

 

I'm playing around with a super simple demo Simeon Bateman posted on his
blog (http://blog.
http://blog.simb.net/2009/05/01/flex-101-back-to-the-basics/
simb.net/2009/05/01/flex-101-back-to-the-basics/)

 

It's just a little tool designed to teach basic MVC / OO principles to newbs
like me. I've get what it's doing and why it works, now I'm trying to extend
on it.

 

 

I'm trying to take this custom component and instead of displaying it in the
main app, open it in a pop up window.

 

view:UserForm userSubmit=onSubmit(event)/

 

 

 I can get it to do that just fine, but I cannot get the custom event
registered with the addEventListener. I get the following error message:


1119: Access of possibly undefined property USER_SUBMIT through a reference
with static type Class.

 

 

 

Any thoughts? It works properly when I use it as is in MXML form, but not
when I try to create the object using AS.

 

 

private function openWindow():void {

win =
view.UserForm(PopUpManager.createPopUp(this, UserForm, false));

 
PopUpManager.centerPopUp(win);

 
win.addEventListener(UserEvents.USER_SUBMIT, onSubmit);

}


-- 
Alan Rother
Adobe Certified Advanced ColdFusion MX 7 Developer
Manager, Phoenix Cold Fusion User Group, AZCFUG.org





Re: [flexcoders] Newbie question: Custom Components and Custom Events

2009-05-04 Thread Alan Rother
Did you import UserEvents?

Yep...

?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=vertical
xmlns:local=* xmlns:view=view.*
mx:Script
![CDATA[
import view.UserForm;
import events.UserEvents;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.managers.PopUpManager;
 [Bindable]
private var users:ArrayCollection = new ArrayCollection();
 private var win:UserForm = new UserForm();
 private function onSubmit(event:UserEvents):void {
users.addItem(event.user);
}
 private function openWindow():void {
win = view.UserForm(PopUpManager.createPopUp(this, UserForm, false));
PopUpManager.centerPopUp(win);
win.addEventListener(UserEvents.USER_SUBMIT, onSubmit);
}
]]
/mx:Script
mx:DataGrid dataProvider={users}/
view:UserForm userSubmit=onSubmit(event)/
mx:Button label=click me click=openWindow()/
/mx:Application


-- 
Alan Rother
Adobe Certified Advanced ColdFusion MX 7 Developer
Manager, Phoenix Cold Fusion User Group, AZCFUG.org


Re: [flexcoders] Newbie question: Custom Components and Custom Events

2009-05-04 Thread Sam Lai
Looks like the USER_SUBMIT variable or constant in your UserEvents
class is not static, but you're accessing it in a static way.

They should be static, so add they keyword static before the var
keyword when you declare USER_SUBMIT and it should all work.

On 5/5/09, Alan Rother alan.rot...@gmail.com wrote:
 Hey All,
 I'm playing around with a super simple demo Simeon Bateman posted on his
 blog
 (http://blog.simb.net/2009/05/01/flex-101-back-to-the-basics/)http://blog.simb.net/2009/05/01/flex-101-back-to-the-basics/

 It's just a little tool designed to teach basic MVC / OO principles to newbs
 like me. I've get what it's doing and why it works, now I'm trying to extend
 on it.


 I'm trying to take this custom component and instead of displaying it in the
 main app, open it in a pop up window.

 view:UserForm userSubmit=onSubmit(event)/


  I can get it to do that just fine, but I cannot get the custom event
 registered with the addEventListener. I get the following error message:

 1119: Access of possibly undefined property USER_SUBMIT through a reference
 with static type Class.



 Any thoughts? It works properly when I use it as is in MXML form, but not
 when I try to create the object using AS.


 private function openWindow():void {
 win = view.UserForm(PopUpManager.createPopUp(this, UserForm, false));
 PopUpManager.centerPopUp(win);
 win.addEventListener(UserEvents.USER_SUBMIT, onSubmit);
 }

 --
 Alan Rother
 Adobe Certified Advanced ColdFusion MX 7 Developer
 Manager, Phoenix Cold Fusion User Group, AZCFUG.org


-- 
Sent from my mobile device


RE: [flexcoders] Newbie question: Custom Components and Custom Events

2009-05-04 Thread Tracy Spratt
Yes, as Sam says.

 

Also, you could look in the UserEvents code to see what the value of that
constant is and use that string.

 

Tracy Spratt,

Lariat Services, development services available

  _  

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of Sam Lai
Sent: Monday, May 04, 2009 7:11 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Newbie question: Custom Components and Custom
Events

 






Looks like the USER_SUBMIT variable or constant in your UserEvents
class is not static, but you're accessing it in a static way.

They should be static, so add they keyword static before the var
keyword when you declare USER_SUBMIT and it should all work.

On 5/5/09, Alan Rother alan.rother@ mailto:alan.rother%40gmail.com
gmail.com wrote:
 Hey All,
 I'm playing around with a super simple demo Simeon Bateman posted on his
 blog
 (http://blog.
http://blog.simb.net/2009/05/01/flex-101-back-to-the-basics/
simb.net/2009/05/01/flex-101-back-to-the-basics/)http://blog.
http://blog.simb.net/2009/05/01/flex-101-back-to-the-basics/
simb.net/2009/05/01/flex-101-back-to-the-basics/

 It's just a little tool designed to teach basic MVC / OO principles to
newbs
 like me. I've get what it's doing and why it works, now I'm trying to
extend
 on it.


 I'm trying to take this custom component and instead of displaying it in
the
 main app, open it in a pop up window.

 view:UserForm userSubmit=onSubmit(event)/


 I can get it to do that just fine, but I cannot get the custom event
 registered with the addEventListener. I get the following error message:

 1119: Access of possibly undefined property USER_SUBMIT through a
reference
 with static type Class.



 Any thoughts? It works properly when I use it as is in MXML form, but not
 when I try to create the object using AS.


 private function openWindow():void {
 win = view.UserForm(PopUpManager.createPopUp(this, UserForm, false));
 PopUpManager.centerPopUp(win);
 win.addEventListener(UserEvents.USER_SUBMIT, onSubmit);
 }

 --
 Alan Rother
 Adobe Certified Advanced ColdFusion MX 7 Developer
 Manager, Phoenix Cold Fusion User Group, AZCFUG.org


-- 
Sent from my mobile device





Re: [flexcoders] Newbie question: Custom Components and Custom Events

2009-05-04 Thread Alan Rother
This is the entire UserEvents class as the example showed me how to build
it. I'm guessing that the declaration for my event is supposed to be in
here, but in the demo we actually created it in the component we were
loading. How and where do I add it to the UserEvents class and why does it
work when I call it from MXML but not from AS?
//File: UserEvents.as
package events
{
import flash.events.Event;
import vo.User;

public class UserEvents extends Event
{
public var user:User;
 public function UserEvents(type:String, bubbles:Boolean=false,
cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
 }
}


//Script Code from Component
mx:Metadata
[Event(name=userSubmit, type=events.UserEvents)]
/mx:Metadata
mx:Script
![CDATA[
import vo.User;
import events.UserEvents;
import mx.managers.PopUpManager;
 private function onClick():void {
var event:UserEvents = new UserEvents(userSubmit);
var user:User = new User();
user.fname = fname.text;
user.lname = lname.text;
user.email = email.text;
event.user = user;
dispatchEvent(event);
}
]]
/mx:Script

-- 
Alan Rother
Adobe Certified Advanced ColdFusion MX 7 Developer
Manager, Phoenix Cold Fusion User Group, AZCFUG.org


RE: [flexcoders] Newbie question: Custom Components and Custom Events

2009-05-04 Thread Tracy Spratt
This metadata makes it available in mxml:

[Event(name=userSubmit, type=events.UserEvents)]

 

But the syntax UserEvents.USER_SUBMIT requires a contant in that class:

public class UserEvents extends Event

{

  public static const USER_SUBMIT:String = userSubmit;

 

Using a constant like that just ensures you won't misspell userSubmit.

 

Tracy Spratt,

Lariat Services, development services available

  _  

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of Alan Rother
Sent: Monday, May 04, 2009 8:15 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Newbie question: Custom Components and Custom
Events

 






This is the entire UserEvents class as the example showed me how to build
it. I'm guessing that the declaration for my event is supposed to be in
here, but in the demo we actually created it in the component we were
loading. How and where do I add it to the UserEvents class and why does it
work when I call it from MXML but not from AS?

 

//File: UserEvents.as

package events

{

import flash.events.Event;  

import vo.User;

 

public class UserEvents extends Event

{

public var user:User;



public function UserEvents(type:String,
bubbles:Boolean=false, cancelable:Boolean=false)

{

super(type, bubbles, cancelable);

}



}

}

 

 

//Script Code from Component

mx:Metadata

[Event(name=userSubmit, type=events.UserEvents)]

/mx:Metadata

mx:Script

![CDATA[

import vo.User;

import events.UserEvents;

import mx.managers.PopUpManager;



private function onClick():void {

var event:UserEvents = new
UserEvents(userSubmit);

var user:User = new User();

user.fname = fname.text;

user.lname = lname.text;

user.email = email.text;

event.user = user;

dispatchEvent(event);

}

]]

/mx:Script


-- 
Alan Rother
Adobe Certified Advanced ColdFusion MX 7 Developer
Manager, Phoenix Cold Fusion User Group, AZCFUG.org