Layer Display Hierarchy using AS3 MouseEvents
I posted this issue a while back but the feedback didn't work out so reposting after trying some new solutions. See detail below:
I've got a virtual desktop environment that will allow users to click, drag and drop windows in the desktop. The OS Toolbar layer always stays on top (like an actual desktop). Additionally, I want the user to be able to select from 4 different desktop backgrounds.
In terms of drag/drop and a single desktop background I have this working. Where I'm running into issues is a method for selecting different desktop BG's.
CLAY suggested using myDesktopContainingMovieClip.gotoAndStop(1), 2, 3, instead of 'addChild' method for keeping the 'toolBar' layer on top but this didn't work for me either as my DragDrop functionality stopped.
I'm currently working with having 4 consecutive keyframes in the Timeline. Each keyframe has one of the 4 unique desktop BG's. I'm using a stop(); command to keep the playhead on any given BG and using keyCodes to advance to each of the frames 1 thru 4. Problem now is that the drag and drop doesn't work using this method either (per script below).
Note: Each keyframe has its own actions frame above with unique script for that frame. I'm using unique MC's and Instance names for each frame (which reference the original media that was imported to the library).
I think the issue is the 'addChild' command to keep the toolbar on top of the other layers.
Any advice at this point is greatly appreciate! Thanks!
Here is my script for Frames 1 & 2 (to show how I'm going about this):
FRAME 1:
// To make the Projector launch FULL SCREEN
stage.displayState = StageDisplayState.FULL_SCREEN;
// Stops the playhead at the current frame
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(e:Event):void {
if (currentFrame == 1) stop();
}
// _____________________________________________________________________
// Event Listener for MouseDown with variable name of 'lab1Start'
sequencer1.addEventListener(MouseEvent.MOUSE_DOWN, lab1Start);
function lab1Start(e:MouseEvent):void {
// 1st addChild makes the MC instance, 'sequencer1' appear on top'
addChild(DisplayObject(e.currentTarget));
// the second addChild forces the MC instance, 'toolBar' to always be on top no matter what's clicked
addChild(toolBar);
sequencer1.startDrag();
}
// this is the 'drop' part of the drag & drop that's cue'd by a Mouse_Up event.
sequencer1.addEventListener(MouseEvent.MOUSE_UP, lab1Stop);
function lab1Stop(e:MouseEvent):void {
sequencer1.stopDrag();
}
// _____________________________________________________________________
// Event Listener for MouseDown with variable name of 'lab2Start'
sequencer2.addEventListener(MouseEvent.MOUSE_DOWN, lab2Start);
function lab2Start(e:MouseEvent):void {
// 1st addChild makes the MC instance, 'sequencer2' appear on top'
addChild(DisplayObject(e.currentTarget));
// the second addChild forces the MC instance, 'toolBar' to always be on top no matter what's clicked
addChild(toolBar);
sequencer2.startDrag();
}
// this is the 'drop' part of the drag & drop that's cue'd by a Mouse_Up event.
sequencer2.addEventListener(MouseEvent.MOUSE_UP, lab2Stop);
function lab2Stop(e:MouseEvent):void {
sequencer2.stopDrag();
}
//navigate frames using '1' and '2' keys
stage.addEventListener(KeyboardEvent.KEY_DOWN, tester)
function tester(e:KeyboardEvent):void
{
if(e.keyCode == 49)
{
gotoAndPlay(1);
}
else if(e.keyCode == 50)
{
gotoAndPlay(2);
}
}
function reportKeyDown(e:KeyboardEvent):void
{
trace(e.keyCode);
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
FRAME 2:
// To make the Projector launch FULL SCREEN
stage.displayState = StageDisplayState.FULL_SCREEN;
addEventListener(Event.ENTER_FRAME, onEnterFrame2);
function onEnterFrame2(e:Event):void {
if (currentFrame == 2) stop();
}
// _____________________________________________________________________
// Event Listener for MouseDown with variable name of 'lab5Start'
sequencer1a.addEventListener(MouseEvent.MOUSE_DOWN, lab5Start);
function lab5Start(e:MouseEvent):void {
// 1st addChild makes the MC instance, 'sequencer1a’ appear on top'
addChild(DisplayObject(e.currentTarget));
// the second addChild forces the MC instance, 'toolBar' to always be on top no matter what's clicked
addChild(toolBarB);
sequencer1a.startDrag();
}
// this is the 'drop' part of the drag & drop that's cue'd by a Mouse_Up event.
sequencer1a.addEventListener(MouseEvent.MOUSE_UP, lab5Stop);
function lab5Stop(e:MouseEvent):void {
sequencer1a.stopDrag();
}
// _____________________________________________________________________
sequencer2a.addEventListener(MouseEvent.MOUSE_DOWN, lab6Start);
function lab6Start(e:MouseEvent):void {
// 1st addChild makes the MC instance, 'sequencer2a’ appear on top'
addChild(DisplayObject(e.currentTarget));
// the second addChild forces the MC instance, 'toolBar' to always be on top no matter what's clicked
addChild(toolBarB);
sequencer2a.startDrag();
}
sequencer2a.addEventListener(MouseEvent.MOUSE_UP, lab6Stop);
function lab6Stop(e:MouseEvent):void {
sequencer2a.stopDrag();
}
//navigate frames
stage.addEventListener(KeyboardEvent.KEY_DOWN, tester)
function tester(e:KeyboardEvent):void
{
if(e.keyCode == 49)
{
gotoAndPlay(1);
}
else if(e.keyCode == 50)
{
gotoAndPlay(2);
}
}
