0
votes

I am new to Flash and Actionscript. I have a movie that is initiated from a C# program. In the movie I am creating different textfields and passing the data back to the C# program. I also have a hotspot that when it is clicked I want to create a small menu that pops up. I've looked at a number of ways to do this and I decided that the easiest way to do this (or so I thought) would be to create a couple of buttons right under the hotspot. For some reason the buttons do not show up on the stage when I click on the hot spot. I know it is going through the routine that creates the buttons because I display a message. I have posted my code. Thanks for the help!!

import flash.text.TextField;
import fl.controls.Button; 
import flash.events.Event;

hotSpot.addEventListener(MouseEvent.CLICK, showMenu);

var continueBtn:Button;
var exitBtn:Button;

function showMenu(evt: Event):void
{
    continueBtn = new Button();

    continueBtn.x = 20;
    continueBtn.y = 100;
    continueBtn.width = 30;
    continueBtn.height = 20;
    continueBtn.border = true;
    continueBtn.visible = true;
    continueBtn.label = "Continue";
    addChild(continueBtn);

    exitBtn = new Button();

    exitBtn.x = continueBtn.x;
    exitBtn.y = continueBtn.y + continueBtn.height;
    exitBtn.width = 30;
    exitBtn.height = 20; 
    exitBtn.border = true;
    exitBtn.visible = true;
    exitBtn.label = "Exit";
    addChild(exitBtn);

    continueBtn.addEventListener(MouseEvent.CLICK, sendMsg);
    exitBtn.addEventListener(MouseEvent.CLICK, endFlash);

    inTxt.text = "showMenu";

}

The message "showMenu" is displayed but neither one of the buttons show.

Gary

1
Are you getting any compile errors when you run this code? I can't find the property border of the Button as3 class livedocs.adobe.com/flash/9.0_es/ActionScriptLangRefV3/fl/… - danii
Does your project library contain any of the assets needed for a button? - Amy Blankenship

1 Answers

0
votes
function showMenu(evt: Event):void

The evt must be a "MouseEvent" instead of "Event" because the listener you added to the "hotSpot" sprite (probably, or other display object) is a MouseEvent not an Event.

hotSpot.addEventListener(MouseEvent.CLICK, showMenu);

This calls the showMenu function which listens and catch the MouseEvent and not the Event event.

You also imported only the Event, import the MouseEvent instead! New Code:

import flash.text.TextField;
import fl.controls.Button; 
import flash.events.MouseEvent; //This line changed!

hotSpot.addEventListener(MouseEvent.CLICK, showMenu);
var continueBtn:Button;
var exitBtn:Button;
 //This line changed!
function showMenu(evt:MouseEvent):void{
continueBtn = new Button();
continueBtn.x = 20;
continueBtn.y = 100;
continueBtn.width = 30;
continueBtn.height = 20;
continueBtn.border = true;
continueBtn.visible = true;
continueBtn.label = "Continue";
addChild(continueBtn);

exitBtn = new Button();

exitBtn.x = continueBtn.x;
exitBtn.y = continueBtn.y + continueBtn.height;
exitBtn.width = 30;
exitBtn.height = 20; 
exitBtn.border = true;
exitBtn.visible = true;
exitBtn.label = "Exit";
addChild(exitBtn);

continueBtn.addEventListener(MouseEvent.CLICK, sendMsg);
exitBtn.addEventListener(MouseEvent.CLICK, endFlash);

inTxt.text = "showMenu";
}