My script has a structure like this (shorten down version):
MenuDisplay.as (creates the menu)
PHP Code:
package
{
import flash.display.Graphics;
import flash.display.BitmapData;
import Array;
//
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
public class MenuDisplay extends Sprite
{
public function makeMenu () : void
{
addChild (menuAct);
// make the menu here
}
// functions for creating the menu items here...
}
}
For making it easier to navigate the code I moved the functions for the buttons into a new class MenuActions.as:
PHP Code:
package
{
import flash.display.Graphics;
import flash.display.BitmapData;
import Array;
//
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Graphics;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.display.Sprite;
//import flash.display.Stage;
import flash.display.*;
import flash.events.*;
public class MenuActions extends Sprite
{
var backgroundNoise = new StaticNoise ();
// Functions for menu items
public function startProgram (e : MouseEvent) : void
{
backgroundNoise.CreateStaticNoise ();
addChild (backgroundNoise);
// Set focus to stage
backgroundNoise.addEventListener (KeyboardEvent.KEY_DOWN, backgroundNoise.checkKey);
}
}
}
The problem here is that the keys are not picked up. Earlier when I had the code in the MenuDisplay class, everything worked fine by doing:
PHP Code:
addChild (backgroundNoise);
stage.addEventListener (KeyboardEvent.KEY_DOWN, backgroundNoise.checkKey);
// Set focus to stage
stage.focus = stage;
but the stage is null, and if I try Stage.addEventListener... or Stage.focus, I receive an error.
as an weekend coder, I'm not sure if I'm structuring my code right