This has literally been buggin me for days. I cant get my custom event “selectionEvent” to work. It works in the DocumentClass constructor, but when trying to dispatch from a child object it doesnt recieve!!!
also in my other thread about custom events, If I try to add the listener to the child object, it just says “undefined property loadplayscreen”.
DocumentClass: (dispatches fine here)
EDIT: updated (little change)
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class DocumentClass extends MovieClip
{
//New Constructor
public var fighter:Fighter = new Fighter;
public var playscreen:FightingGame;
public var platform:Platform = new Platform;
public var selectionScreen:SelectionScreen;
public var selectedCharacter:int;
public function DocumentClass()
{
addEventListener(Event.ADDED_TO_STAGE, FightingGameBuild, false, 0, true);
addEventListener(SelectionEvent.PLAYSCREEN,loadPlayScreen);
}
//Old Constructor
public function FightingGameBuild(event:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, FightingGameBuild);
trace("new constructor");
selectionScreen = new SelectionScreen;
playscreen = new FightingGame;
selectionScreen.addEventListener(SelectionEvent.PLAYSCREEN,loadPlayScreen);
loadSelectionScreen();
}
public function loadPlayScreen(e:SelectionEvent):void
{
if (playscreen)
{
trace("loaded");
removeChild(selectionScreen);
playscreen = new FightingGame;
addChild(playscreen);
}
else
{
trace("failed");
}
}
public function loadSelectionScreen(selectionevent:SelectionEvent):void
{
if (selectionScreen)
{
trace("selection Screen");
addChild(selectionScreen);
selectionScreen.x = 260;
selectionScreen.y = 250;
}
else
{
trace("failed");
}
}
}
}
Here is the SelectionScreen Class:
package {
import flash.display.MovieClip;
public class SelectionScreen extends MovieClip {
public var selectedCharacter:int;
public var selectarrow:SelectArrow = new SelectArrow;
public function SelectionScreen() {
trace(selectedCharacter);
addChild(selectarrow);
selectarrow.x = 300;
selectarrow.y = 300;
}
}
}
The selectArrow Class (which is dispatching the event)
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class SelectArrow extends MovieClip {
public function SelectArrow() {
this.addEventListener(MouseEvent.CLICK,clickbox);
}
public function clickbox(e:MouseEvent):void
{
dispatchEvent(new SelectionEvent(SelectionEvent.PLAYSCREEN));
trace("clicked");
}
}
}
And finally the SelectionBox class ( I dont know if this one is important.)
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
{
public class _select_StickMan extends MovieClip {
public var playscreen:FightingGame;
public var selectedCharacter:int;
public var selectionscreen:SelectionScreen;
public function _select_StickMan() {
for(var i:int=0;i<9;i++){
this.addEventListener(MouseEvent.CLICK,clickbox);
}
}
function clickbox(e:MouseEvent):void{
trace(e.currentTarget.name);
trace(e.currentTarget.name.substr(3));
(this.parent as MovieClip).selectedCharacter = (e.currentTarget.name.substr(3));
}
}
}
}
Please note that this is supposed to be a fighting game, and its supposed to function like a Character SElection Screen.