Sean Moran
Sean Moran

Reputation: 1

Having issues with event on click

I have a button instance named "instructionButton" and I'm trying to trace "Clicked." to the output when it is clicked as a test but I haven' been successful thus far. Is there something I'm missing?

I'm using code in Flash Pro 6

import flash.events.MouseEvent;

var clickedVar:String = "Clicked.";
var runVar:String = "mice running...";


trace(runVar);

function instructionOpen(event:MouseEvent):void
{
    trace(clickedVar);
    gotoAndPlay(255);
}

instructionsButton.addEventListener (MouseEvent.CLICK, instructionOpen);

And of course if there's a more simple way to approach this, all knowledge will be helpful.

Upvotes: 0

Views: 76

Answers (3)

Ilya Gazman
Ilya Gazman

Reputation: 32221

The only way this will not work is if you are not reaching this frame.

Try add this code on your first frame and tell me if this helping.

Upvotes: 0

Ryan Hollingsworth
Ryan Hollingsworth

Reputation: 381

I don't really see anything wrong with your button code, but here's how i do mine in AS3, it may help :) Creating a simple function within the event listener, I use stopPropgation to prevent my button from clicking anything that may be below it in the flash file. ( say you have two buttons on top of one another, you'll click both instead of one)

instructionsButton.addEventListener(MouseEvent.CLICK, function(e){
    e.stopPropagation();
    trace("Clicked.");
    gotoAndPlay(255);
    });

This is one button, if you need say fifteen, let me know as I have a code sample I'll give you that i use to create a limitless amount of buttons and eventlistners using switch/case which has been a huge help to me :)

Upvotes: 0

sureshunivers
sureshunivers

Reputation: 1753

  1. Check instance name is provided or not in the property window for the button (click the button and go to menu 'Window->Properties' to open property window)

  2. What name is mentioned in the property window for the button, should use the same instance name in action script coding. Ensure the spelling from both script(code) and property window instance name.

Upvotes: 1

Related Questions