3 Replies Latest reply on Oct 24, 2012 12:17 PM by Gaius Coffey

    Event Handler not Working

    KoopaParatroopa

      Salutations!

       

      My College teacher was telling me about flash builder and how good it is for mobile applications. I've never done anything with actionscript before and had my first foray into such a few days ago. However I quickly ran into a problem. I've drawn a rectangle and are now wanting to try and use event handlers. For now I was wanting to say add the event handler for clicking on the rectangle. When done so then run a specifed function.

       

      rectangle.addEventListener(MouseEvent.CLICK, RectClicked);

       

      But even though there is nothing wrong anywhere in my application upon clicking the first rectangle, nothing happens. This is true for other mouse and keyboard events. My teacher said it may have something to do with having the student flash builder at College and currently having the trial here at home. It may not allow you to use certain functions.

       

      Do I have to purchase flash builder first before being able to use certain functionality?

        • 1. Re: Event Handler not Working
          Gaius Coffey Level 2

          Ah... with all due respect, I think your teacher is wrong. To disable event handling would be somewhat traumatic for Flash which uses event handling as the core of its functionality. In any case, I am not aware of any functions being disabled on a trial version.

           

          It is far more likey to be a coding error on your part, sorry. There are a number of possibilities:

          1. You may have drawn a rectangle as a primitive (eg <s:Rect />) or as a Shape - both of which are IEventDispatcher but neither of which dispatch mouse events.

          2. You may have added the listener at the wrong point in the timeline so that the listener isn't there when you click.

          3. Some other, unspecified coding error...

           

          I imagine the first possibility is the most likely.

           

          Here is a simple pure actionscript clicker:

          [code]

          package

          {

          import flash.display.Sprite;

          import flash.events.MouseEvent;

          public class Clicker extends Sprite

          {

            public function Clicker()

            {

             var s:Sprite = new Sprite();

             s.graphics.beginFill(0xff,1);

             s.graphics.drawRect(0,0,50,50);

             s.x = s.y = 50;

             addChild(s);

             s.addEventListener(MouseEvent.CLICK,rectClicked);

            }

            protected function rectClicked(event:MouseEvent):void {

             trace("Rectangle was clicked.");

            }

          }

          }

           

           

           

           

           

           

           

           

          [/code]

          And here is the same in Flex:

          [code]

          <?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[

             import mx.graphics.SolidColor;

            

             protected function group1_clickHandler(event:MouseEvent):void

             {

              trace("Rectangle was clicked.");

             }

            

            ]]>

          </fx:Script>

          <fx:Declarations>

            <!-- Place non-visual elements (e.g., services, value objects) here -->

          </fx:Declarations>

          <s:Group x="50" y="50" click="group1_clickHandler(event)">

            <s:Rect width="50" height="50" fill="{new SolidColor(0xff,1)}" />

          </s:Group>

          </s:Application>

          [/code]

          G

          • 2. Re: Event Handler not Working
            KoopaParatroopa Level 1

            I've tried both your actionscript and flex example in a completly new and seperate project. I've tried on my College's computers as well as my own. I also tried just now compiling the flex application to flash format. On all counts I can click, click, click 'till the cows come home. Nothing happens? I got the trial from the adobe website and there were no problems installing it. I also tried using it on Windows eight via USB again to no avail.

            • 3. Re: Event Handler not Working
              Gaius Coffey Level 2

              Hi Koopa,

              Both the examples I uploaded work, so...

              When you are in FlashBuilder, there are a number of different default options to run.

              1. There is a "Debug" option

              2. There is a "Run" option

              3. There is a "Profile" option (may only be available in Pro versions)

               

              The "Debug" option runs with traces included and connects to the debugger plugin in whatever browser you are using (provided you have _installed_ the debugger player http://www.adobe.com/support/flashplayer/downloads.html ). THIS IS THE OPTION YOU WANT if you want to see traces.

               

              The "Play" option just fires up the movie and has no connection to the debugger.

               

              The "Profile" option is almost certainly a bit more than you are ready for.

               

              Check, then double-check, what you are running and you should see it all working.

              G