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

Event Handler not Working

New Here ,
Oct 23, 2012 Oct 23, 2012

Copy link to clipboard

Copied

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?

Views

561

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

correct answers 1 Correct answer

Enthusiast , Oct 24, 2012 Oct 24, 2012

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 OPTIO

...

Votes

Translate

Translate
Enthusiast ,
Oct 24, 2012 Oct 24, 2012

Copy link to clipboard

Copied

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:

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.");

  }

}

}

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

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
New Here ,
Oct 24, 2012 Oct 24, 2012

Copy link to clipboard

Copied

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.

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
Enthusiast ,
Oct 24, 2012 Oct 24, 2012

Copy link to clipboard

Copied

LATEST

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

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