Re: [flexcoders] help w/ setting click events on dynamically created linkbuttons

2008-09-25 Thread Haykel BEN JEMIA
Use addEventListener() for registering an event handler:
myLabel.addEventListener(MouseEvent.CLICK,
myFunction);You should take time to read about event handling in Flex/AS3 as
it's a basic and very important concept!


On Thu, Sep 25, 2008 at 4:33 PM, Ramsey, Robert L
[EMAIL PROTECTED]wrote:

Hi,



 I am working on a scheduling application and need some help working with
 dynamically created clickable objects.  I've been using linkbuttons, but
 anything that is clickable will work.



 I have an array that may contain 0-N items, where N can be any number.  If
 N0, I need to create clickable linkbuttons that call a function.   What I'm
 doing is something like this:



   *for* *each* (*var* conflict:String *in* conflictArray)

   {

 *var* myLabel:LinkButton = *new* LinkButton;

 myLabel.label = conflict;

 myLabel.y = myy;



 myy += 20;


 Application.application.conflictsPanel.addChild(myLabel);



   }



 What I need to do is have each linkbutton call a function when it is
 clicked and pass two variables to that function.  What I'd like to be able
 to do is something like this:



 myLabel.onClick(myFunction(label, label.length);



 Is there an easy way to do this or a different clickable control I should
 be using?



 Thanks,



 Bob

  




-- 
Haykel Ben Jemia

Allmas
Web  RIA Development
http://www.allmas-tn.com


RE: [flexcoders] help w/ setting click events on dynamically created linkbuttons

2008-09-25 Thread Ramsey, Robert L
I have looked through the examples, and that’s what is confusing me. 

 

All of the examples show exactly what you have written:

 

myFunction(event:MouseEvent)

{

Alert.show(“hello world”);

}

 

 

myLabel.addEventListener(MouseEvent.CLICK, myFunction);

 

 

When I try to do this:

 

myFunction(event:MouseEvent, myString:String)

{

//do something here

Alert.show(myString);

}

 

myLabel.addEventListener(MouseEvent.CLICK, myFunction(MouseEvent.CLICK, 
“hello”);

 

I get the following error:

1067: Implicit coercion of a value of type String to an unrelated type 
flash.events:MouseEvent.

 

The problem I’m having is finding the correct syntax to use when passing the 
string to myFunction.

 

Can you point me to the part of the manuals that would help me with that?

 

Thanks,

 

Bob

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Haykel 
BEN JEMIA
Sent: Thursday, September 25, 2008 9:56 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] help w/ setting click events on dynamically created 
linkbuttons

 

Use addEventListener() for registering an event handler: 
myLabel.addEventListener(MouseEvent.CLICK, myFunction);

You should take time to read about event handling in Flex/AS3 as it's a basic 
and very important concept!

 

 

On Thu, Sep 25, 2008 at 4:33 PM, Ramsey, Robert L [EMAIL PROTECTED] wrote:

Hi,

 

I am working on a scheduling application and need some help working with 
dynamically created clickable objects.  I've been using linkbuttons, but 
anything that is clickable will work.

 

I have an array that may contain 0-N items, where N can be any number.  If N0, 
I need to create clickable linkbuttons that call a function.   What I'm doing 
is something like this:

 

  for each (var conflict:String in conflictArray)

  {

var myLabel:LinkButton = new LinkButton;

myLabel.label = conflict;

myLabel.y = myy;



myy += 20;


Application.application.conflictsPanel.addChild(myLabel);



  }

 

What I need to do is have each linkbutton call a function when it is clicked 
and pass two variables to that function.  What I'd like to be able to do is 
something like this:

 

myLabel.onClick(myFunction(label, label.length);

 

Is there an easy way to do this or a different clickable control I should be 
using?

 

Thanks,

 

Bob




-- 
Haykel Ben Jemia

Allmas
Web  RIA Development
http://www.allmas-tn.com



 

image001.jpgimage002.jpg

Re: [flexcoders] help w/ setting click events on dynamically created linkbuttons

2008-09-25 Thread Haykel BEN JEMIA
You can't pass any variables to the handler that way. The event handler
function must have exactly one argument, the event object, or no arguments.
If you need a reference to the clicked button for example, you can get it in
the handler with event.target.Doc:
http://livedocs.adobe.com/flex/3/html/events_01.html



On Thu, Sep 25, 2008 at 5:12 PM, Ramsey, Robert L
[EMAIL PROTECTED]wrote:

I have looked through the examples, and that's what is confusing me.



 All of the examples show exactly what you have written:



 myFunction(event:MouseEvent)

 {

 Alert.show(hello world);

 }





 myLabel.addEventListener(MouseEvent.CLICK, myFunction);





 When I try to do this:



 myFunction(event:MouseEvent, myString:String)

 {

 //do something here

 Alert.show(myString);

 }



 myLabel.addEventListener(MouseEvent.CLICK, myFunction(MouseEvent.CLICK,
 hello);



 I get the following error:

 1067: Implicit coercion of a value of type String to an unrelated type
 flash.events:MouseEvent.



 The problem I'm having is finding the correct syntax to use when passing
 the string to myFunction.



 Can you point me to the part of the manuals that would help me with that?



 Thanks,



 Bob



 *From:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On
 Behalf Of *Haykel BEN JEMIA
 *Sent:* Thursday, September 25, 2008 9:56 AM
 *To:* flexcoders@yahoogroups.com
 *Subject:* Re: [flexcoders] help w/ setting click events on dynamically
 created linkbuttons



 Use addEventListener() for registering an event handler: 
 myLabel.addEventListener(MouseEvent.CLICK,
 myFunction);

 You should take time to read about event handling in Flex/AS3 as it's a
 basic and very important concept!





 On Thu, Sep 25, 2008 at 4:33 PM, Ramsey, Robert L [EMAIL PROTECTED]
 wrote:

 Hi,



 I am working on a scheduling application and need some help working with
 dynamically created clickable objects.  I've been using linkbuttons, but
 anything that is clickable will work.



 I have an array that may contain 0-N items, where N can be any number.  If
 N0, I need to create clickable linkbuttons that call a function.   What I'm
 doing is something like this:



   *for* *each* (*var* conflict:String *in* conflictArray)

   {

 *var* myLabel:LinkButton = *new* LinkButton;

 myLabel.label = conflict;

 myLabel.y = myy;



 myy += 20;


 Application.application.conflictsPanel.addChild(myLabel);



   }



 What I need to do is have each linkbutton call a function when it is
 clicked and pass two variables to that function.  What I'd like to be able
 to do is something like this:



 myLabel.onClick(myFunction(label, label.length);



 Is there an easy way to do this or a different clickable control I should
 be using?



 Thanks,



 Bob




 --
 Haykel Ben Jemia

 Allmas
 Web  RIA Development
 http://www.allmas-tn.com

  




-- 
Haykel Ben Jemia

Allmas
Web  RIA Development
http://www.allmas-tn.com


RE: [flexcoders] help w/ setting click events on dynamically created linkbuttons

2008-09-25 Thread Ramsey, Robert L
I did finally find the syntax this morning:

 

http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetailsproductId=2postId=9144

 

ABCButton.addEventListener(MouseEvent.CLICK,function (e:MouseEvent) : void 
{ABCButtonListener(e,myPrivateSpecialObject);});

 

 

Using this syntax, I can pass variables to the CLICK event handler.  Of course, 
since I was iterating through an Array as I was creating the linkbuttons, it 
ended up using the value of the last entry in the Array for all of the values.  
Argh.

 

For this task, I’m shifting to radio buttons and a submit button.  I think it 
will be easier on me.

 

Thanks,

 

Bob

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Haykel 
BEN JEMIA
Sent: Thursday, September 25, 2008 10:40 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] help w/ setting click events on dynamically created 
linkbuttons

 

You can't pass any variables to the handler that way. The event handler 
function must have exactly one argument, the event object, or no arguments. If 
you need a reference to the clicked button for example, you can get it in the 
handler with event.target.

Doc: http://livedocs.adobe.com/flex/3/html/events_01.html

 

 

 

On Thu, Sep 25, 2008 at 5:12 PM, Ramsey, Robert L [EMAIL PROTECTED] wrote:

I have looked through the examples, and that's what is confusing me. 

 

All of the examples show exactly what you have written:

 

myFunction(event:MouseEvent)

{

Alert.show(hello world);

}

 

 

myLabel.addEventListener(MouseEvent.CLICK, myFunction);

 

 

When I try to do this:

 

myFunction(event:MouseEvent, myString:String)

{

//do something here

Alert.show(myString);

}

 

myLabel.addEventListener(MouseEvent.CLICK, myFunction(MouseEvent.CLICK, 
hello);

 

I get the following error:

1067: Implicit coercion of a value of type String to an unrelated type 
flash.events:MouseEvent.

 

The problem I'm having is finding the correct syntax to use when passing the 
string to myFunction.

 

Can you point me to the part of the manuals that would help me with that?

 

Thanks,

 

Bob

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Haykel 
BEN JEMIA
Sent: Thursday, September 25, 2008 9:56 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] help w/ setting click events on dynamically created 
linkbuttons

 

Use addEventListener() for registering an event handler: 
myLabel.addEventListener(MouseEvent.CLICK, myFunction);

You should take time to read about event handling in Flex/AS3 as it's a basic 
and very important concept!

 

 

On Thu, Sep 25, 2008 at 4:33 PM, Ramsey, Robert L [EMAIL PROTECTED] wrote:

Hi,

 

I am working on a scheduling application and need some help working with 
dynamically created clickable objects.  I've been using linkbuttons, but 
anything that is clickable will work.

 

I have an array that may contain 0-N items, where N can be any number.  If N0, 
I need to create clickable linkbuttons that call a function.   What I'm doing 
is something like this:

 

  for each (var conflict:String in conflictArray)

  {

var myLabel:LinkButton = new LinkButton;

myLabel.label = conflict;

myLabel.y = myy;



myy += 20;


Application.application.conflictsPanel.addChild(myLabel);



  }

 

What I need to do is have each linkbutton call a function when it is clicked 
and pass two variables to that function.  What I'd like to be able to do is 
something like this:

 

myLabel.onClick(myFunction(label, label.length);

 

Is there an easy way to do this or a different clickable control I should be 
using?

 

Thanks,

 

Bob






-- 
Haykel Ben Jemia

Allmas
Web  RIA Development
http://www.allmas-tn.com




-- 
Haykel Ben Jemia

Allmas
Web  RIA Development
http://www.allmas-tn.com



 

image001.jpgimage002.jpg

RE: [flexcoders] help w/ setting click events on dynamically created linkbuttons

2008-09-25 Thread Tracy Spratt
I advise using repeater with a custom clickable component.

Tracy

 

Goal: Display a list of items using a complex display for each item, and
have each of those items behave like a menu element and respond to a
click anywhere on the item by running a handler function.

 

One solution is to use a Repeater with a custom component

 

In the main app or component, declare the Repeater, and the click
handler function.

mx:Application ...

mx:Script![CDATA[

  import MyRepeaterItem;

  ...

  

private function onRPItemClick(oEvent:Event):void

{

var xmlItem:XML = XML(oEvent.target);

 

}//onRPItemClick

]]/mx:Script

  mx:VBox ...

mx:Repeater id=rp dataProvider={_xmlData} ...

  !-- Note we pass in the entire currentItem, and define a click
handler  --

  MyRepeaterItem xmlItem={rp.currentItem}
itemClick=onRPItemClick(event) .../

/mx:Repeater

  /mx:VBox

/mx:Application

 

And in the component, MyRepeaterItem.mxml:

?xml version=1.0 encoding=utf-8?

mx:HBox mouseChildren=false buttonMode=true click=onClick(event)
 

  !-- The metadata tag below allows us to define an itemClick handler
in mxml, as in the code above --

  mx:Metadata

 [Event(name=itemClick, type=flash.events.Event)]

  /mx:Metadata

mx:Script![CDATA[

  [Bindable]private var _xmlItem:XML;

  

  /** Setter function */

  public function set xmlItem(xml:XML):void  

  {

_xmlItem = xml;

//do any special, non-bound ui stuff you want

  }//set xmlItem

 

  /** Getter function */  

  public function get xmlItem():XML  

  {

return _xmlItem;

  }//get xmlItem

 

 

  /** Outer VBox Click handler function */  

  private function onClick():void 

  {

dispatchEvent(new Event(itemClick,false); //we do not need/want
this event to bubble

  }//onClick

 

]]/mx:Script

  !-- Now declare the Item UI --

  mx:Text id=lbDescription text=[EMAIL PROTECTED]
width=100% height=100% /

/mx:HBox

 

 

 

  

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Ramsey, Robert L
Sent: Thursday, September 25, 2008 10:34 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] help w/ setting click events on dynamically
created linkbuttons

 

Hi,

 

I am working on a scheduling application and need some help working with
dynamically created clickable objects.  I've been using linkbuttons, but
anything that is clickable will work.

 

I have an array that may contain 0-N items, where N can be any number.
If N0, I need to create clickable linkbuttons that call a function.
What I'm doing is something like this:

 

  for each (var conflict:String in conflictArray)

  {

var myLabel:LinkButton = new LinkButton;

myLabel.label = conflict;

myLabel.y = myy;



myy += 20;

 
Application.application.conflictsPanel.addChild(myLabel);



  }

 

What I need to do is have each linkbutton call a function when it is
clicked and pass two variables to that function.  What I'd like to be
able to do is something like this:

 

myLabel.onClick(myFunction(label, label.length);

 

Is there an easy way to do this or a different clickable control I
should be using?

 

Thanks,

 

Bob

 



RE: [flexcoders] help w/ setting click events on dynamically created linkbuttons

2008-09-25 Thread Tracy Spratt
A primary benefit of doing things like this is that you have the entire
item data in the component dispatching the event, and you have access to
that data in any handler via the event.target reference.

 

So you only need the event, and no other arguments.

 

Tracy

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Tracy Spratt
Sent: Thursday, September 25, 2008 8:02 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] help w/ setting click events on dynamically
created linkbuttons

 

I advise using repeater with a custom clickable component.

Tracy

 

Goal: Display a list of items using a complex display for each item, and
have each of those items behave like a menu element and respond to a
click anywhere on the item by running a handler function.

 

One solution is to use a Repeater with a custom component

 

In the main app or component, declare the Repeater, and the click
handler function.

mx:Application ...

mx:Script![CDATA[

  import MyRepeaterItem;

  ...

  

private function onRPItemClick(oEvent:Event):void

{

var xmlItem:XML = XML(oEvent.target);

 

}//onRPItemClick

]]/mx:Script

  mx:VBox ...

mx:Repeater id=rp dataProvider={_xmlData} ...

  !-- Note we pass in the entire currentItem, and define a click
handler  --

  MyRepeaterItem xmlItem={rp.currentItem}
itemClick=onRPItemClick(event) .../

/mx:Repeater

  /mx:VBox

/mx:Application

 

And in the component, MyRepeaterItem.mxml:

?xml version=1.0 encoding=utf-8?

mx:HBox mouseChildren=false buttonMode=true click=onClick(event)
 

  !-- The metadata tag below allows us to define an itemClick handler
in mxml, as in the code above --

  mx:Metadata

 [Event(name=itemClick, type=flash.events.Event)]

  /mx:Metadata

mx:Script![CDATA[

  [Bindable]private var _xmlItem:XML;

  

  /** Setter function */

  public function set xmlItem(xml:XML):void  

  {

_xmlItem = xml;

//do any special, non-bound ui stuff you want

  }//set xmlItem

 

  /** Getter function */  

  public function get xmlItem():XML  

  {

return _xmlItem;

  }//get xmlItem

 

 

  /** Outer VBox Click handler function */  

  private function onClick():void 

  {

dispatchEvent(new Event(itemClick,false); //we do not need/want
this event to bubble

  }//onClick

 

]]/mx:Script

  !-- Now declare the Item UI --

  mx:Text id=lbDescription text=[EMAIL PROTECTED]
width=100% height=100% /

/mx:HBox

 

 

 

  

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Ramsey, Robert L
Sent: Thursday, September 25, 2008 10:34 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] help w/ setting click events on dynamically
created linkbuttons

 

Hi,

 

I am working on a scheduling application and need some help working with
dynamically created clickable objects.  I've been using linkbuttons, but
anything that is clickable will work.

 

I have an array that may contain 0-N items, where N can be any number.
If N0, I need to create clickable linkbuttons that call a function.
What I'm doing is something like this:

 

  for each (var conflict:String in conflictArray)

  {

var myLabel:LinkButton = new LinkButton;

myLabel.label = conflict;

myLabel.y = myy;



myy += 20;

 
Application.application.conflictsPanel.addChild(myLabel);



  }

 

What I need to do is have each linkbutton call a function when it is
clicked and pass two variables to that function.  What I'd like to be
able to do is something like this:

 

myLabel.onClick(myFunction(label, label.length);

 

Is there an easy way to do this or a different clickable control I
should be using?

 

Thanks,

 

Bob