• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Flash Builder 4 bug ?

Guest
May 05, 2010 May 05, 2010

Copy link to clipboard

Copied

<?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/mx" minWidth="955" minHeight="600">
     <fx:Script><![CDATA[
     private function init():void {
          button3.addEventListener(MouseEvent.CLICK, handleClick);
     }
     
     private function handleClick(event:MouseEvent):void {
          if (event.target == button3) {
               label.text += 'Buton 3 Clicked\n';

                }

        }
     ]]></fx:Script>
     <s:VGroup width="100%">

                <s:Button id="button3" label="Button 3"/>
          <s:Label id="label"/>
     </s:VGroup>
</s:Application>

The above code does not seem to work.

Views

543

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 06, 2010 May 06, 2010

Copy link to clipboard

Copied

you have a couple of problems with your code... you dont call the init function anywhere, so the addeventlistener never gets initialized...

so you can either add init to the creation complete or initialize in the application tag

and also, when you do event.target, you have to do event.target.id == "button3"

id is a string...

the modifications are as follows...

<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/mx" minWidth="955" minHeight="600" creationComplete="init();">
     <fx:Declarations>
          <!-- Place non-visual elements (e.g., services, value objects) here -->
     </fx:Declarations>
     <fx:Script><![CDATA[
          private function init():void {
               button3.addEventListener(MouseEvent.CLICK, handleClick);
          }
          
          private function handleClick(event:MouseEvent):void {
               if (event.target.id == "button3") {
                    label.text += 'Buton 3 Clicked\n';
               }
          }
     ]]></fx:Script>
     <s:VGroup width="100%">
          <s:Button id="button3" label="Button 3"/>
          <s:Label id="label"/>
     </s:VGroup>

</s:Application>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 06, 2010 May 06, 2010

Copy link to clipboard

Copied

LATEST

The

creationComplete="init();"

is what I needed.

But I did not need:

event.target.id == "button3"

My code now works fine, thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines