Still Struggling with getting this to work - To Recap what I'm trying to accomplish:
I've got a virtual desktop environment that will allow users to click, drag and drop windows in the desktop. The bottom 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 (bottom layer).
CLAY suggested using myDesktopContainingMovieClip.gotoAndStop(1), 2, 3, instead of 'addChild' but this didn't work for me either as my DragDrop functionality stopped.
I'm currently trying by 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 (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.
Here is my script for Frames 1 & 2:
Any advice at this point is greatly appreciate! Thanks!
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);
}
}
SOLVED... I found a solution to this using addChildAt() and not using the timeline at all.
Some background on this solution - I found some forums where people were having similar issues using addChild which seems to create instance errors when used on multiple frames on the timeline. In my case, trying to jump frames where each frame had a unique background image using the same script and instances for the drag/drop windows OR using unique script on each frame and unique instances of the same media on each frame (BOTH APPROACHES) caused instances to multiple each time you changed frames.
I found the 'addChildAt()' command let me do this all with a single frame and AS3. addChildAt() gave me a more granular way to specify exactly where the background layers fall in the stack. So I have the BG layers as 0, 1, 2 & 3 (bottom 4 layers) with the drag drop layers always appearing on top courtesy of a simple addChild. Hope this is helpful to anyone following this thread. I'm sure there are more eloquent solutions with more complex script. Please share if so.