Re: [flexcoders] How does Button 3 knows that it has been clicked in this example?

2009-11-27 Thread Pat Buchanan
Fred:

There are multiple ways to listen for events, such as click events.  Button
1 and button 2 add the listener inline (click=handleClick(event)) in the
MXML markup.

For button 3, the author listens for the even using this line:

button3.addEventListener(MouseEvent.CLICK, handleClick);

It get's called when the app is initialized (initialize=init())

You can delete that line and replace it with the way button 1 and 2 do it if
you want, but both do the exact same thing.

Thanks!
-Pat

On Thu, Nov 26, 2009 at 10:06 AM, fred44455 fred44...@yahoo.com wrote:



 This an example taken out of a Flex 4 book(Amstrong).
 I pretty understand this code but if you look at button3
 at the very end of the code , it has no click(event) associated
 with it. why is that? Will it be ok to add:click=handleClick(event)/
 Like it was done for button2 ??


 Thanks.

 ?xml version=1.0 encoding=utf-8?
 s:Application
 xmlns:fx=http://ns.adobe.com/mxml/2009;
 xmlns:s=library://ns.adobe.com/flex/spark
 xmlns:mx=library://ns.adobe.com/flex/halo
 initialize=init()

 fx:Script![CDATA[
 private function init():void {
 button3.addEventListener(MouseEvent.CLICK, handleClick);
 }
 private function handleClick(event:MouseEvent):void {
 if (event.target == button2) {
 label.text += 'Button 2 clicked\n';
 } else if (event.target == button3) {
 label.text += 'Button 3 clicked\n';
 }
 }
 ]]/fx:Script
 s:VGroup width=100%
 s:Button id=button1 label=Button 1
 click=label.text += 'Button 1 clicked\n'/
 s:Button id=button2 label=Button 2
 click=handleClick(event)/
 s:Button id=button3 label=Button 3/
 s:Label id=label/
 /s:VGroup
 /s:Application

  



[flexcoders] How does Button 3 knows that it has been clicked in this example?

2009-11-26 Thread fred44455
This an example taken out of a Flex 4 book(Amstrong).
I pretty understand this code but if you look at button3
at the very end of the code , it has no click(event) associated
with it. why is that? Will it be ok to add:click=handleClick(event)/ Like it 
was done for button2 ??

Thanks.

?xml version=1.0 encoding=utf-8?
s:Application
xmlns:fx=http://ns.adobe.com/mxml/2009;
xmlns:s=library://ns.adobe.com/flex/spark
xmlns:mx=library://ns.adobe.com/flex/halo
initialize=init()


fx:Script![CDATA[
private function init():void {
button3.addEventListener(MouseEvent.CLICK, handleClick);
}
private function handleClick(event:MouseEvent):void {
if (event.target == button2) {
label.text += 'Button 2 clicked\n';
} else if (event.target == button3) {
label.text += 'Button 3 clicked\n';
}
}
]]/fx:Script
s:VGroup width=100%
s:Button id=button1 label=Button 1
click=label.text += 'Button 1 clicked\n'/
s:Button id=button2 label=Button 2
click=handleClick(event)/
s:Button id=button3 label=Button 3/
s:Label id=label/
/s:VGroup
/s:Application



Re: [flexcoders] How does Button 3 knows that it has been clicked in this example?

2009-11-26 Thread Paul Andrews
fred44455 wrote:
 This an example taken out of a Flex 4 book(Amstrong).
 I pretty understand this code but if you look at button3
 at the very end of the code , it has no click(event) associated
 with it. why is that? Will it be ok to add:click=handleClick(event)/ Like 
 it was done for button2 ??
   
Yes, it looks like an oversight. Just be brave and try!

Paul

 Thanks.

 ?xml version=1.0 encoding=utf-8?
 s:Application
 xmlns:fx=http://ns.adobe.com/mxml/2009;
 xmlns:s=library://ns.adobe.com/flex/spark
 xmlns:mx=library://ns.adobe.com/flex/halo
 initialize=init()


 fx:Script![CDATA[
 private function init():void {
 button3.addEventListener(MouseEvent.CLICK, handleClick);
 }
 private function handleClick(event:MouseEvent):void {
 if (event.target == button2) {
 label.text += 'Button 2 clicked\n';
 } else if (event.target == button3) {
 label.text += 'Button 3 clicked\n';
 }
 }
 ]]/fx:Script
 s:VGroup width=100%
 s:Button id=button1 label=Button 1
 click=label.text += 'Button 1 clicked\n'/
 s:Button id=button2 label=Button 2
 click=handleClick(event)/
 s:Button id=button3 label=Button 3/
 s:Label id=label/
 /s:VGroup
 /s:Application