Error #2025 with Fullscreen Mode Thumbnails
The Jayster Apr 5, 2010 10:25 AMHi Everyone!
My first time on here, and I'm somewhat new to programming AS3, so please go easy. I have a portfolio page on my website (currently in-process) where I display flash samples. To avoid antiquated and uncontrollable pop-ups and js code etc that could be disabled, I went for a very clean/controlled approach by using flash's fullscreen capability. To achieve this, I am using indivdual swfs as thumbnails. Each thumbnail swf listens for a click. Once clicked it fires off its fullscreen mode, loads an external swf file, and positions my assets (the swf file and a custom exit button) perfectly on the screen according to your specific resolution settings. Everything unloads and goes back to normal via a fullscreen event listener, so it doesn't matter how you exit fullscreen mode (via button or escape or whatever). Everything works great in all browsers I've tested, except...
Problem:
In browsers other than Explorer I get the following error when returning to normal mode. Everything works fine, but the error window pops up. Not too impressive on your sample page obviously .
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at thumb_right_moves_fla::MainTimeline/fullScreenRedraw()
at flash.display::Stage/set displayState()
at thumb_right_moves_fla::MainTimeline/exitFullScreen()
Setup:
On the main stage I have a thumbnail movieclip that displays a graphic and provides the rollover effects etc. I also have an Exit movie clip that serves as a button during fullscreen mode. All code is in a single frame in the Actions layer of the main timeline. There is only 1 frame in the FLA.
My Complete Code:
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.FullScreenEvent;
var screenWidth:Number;
var screenHeight:Number;
var sampleWidth:Number = 800; // enter actual external content width
var sampleHeight:Number = 500; // enter actual external content height
var stageWidthAdjustment = stage.stageWidth/2;
var stageHeightAdjustment = stage.stageHeight/2;
var contentURL:String = "swf/sample_right_moves.swf"; // enter url to external content
var screenMargin:Number = 10; // set the prefered distance of exit button from screen edge
var contentRequest:URLRequest = new URLRequest(contentURL);
var contentLoader:Loader = new Loader;
// Initial stage setup
exit_mc.visible = false;
thumb_mc.buttonMode = true;
thumb_mc.addEventListener(MouseEvent.CLICK, enterFullScreen);
thumb_mc.addEventListener(MouseEvent.ROLL_OVER, over);
thumb_mc.addEventListener(MouseEvent.ROLL_OUT, out);
stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenRedraw);
stage.addEventListener(Event.RESIZE, resizeDisplay);
stage.scaleMode = StageScaleMode.NO_SCALE;
// Event handlers
function enterFullScreen(event:MouseEvent):void
{
stage.displayState = StageDisplayState.FULL_SCREEN;
}
function exitFullScreen(event:MouseEvent):void
{
stage.displayState = StageDisplayState.NORMAL;
}
function resizeDisplay(event:Event):void
{
screenWidth = stage.stageWidth;
screenHeight = stage.stageHeight;
}
function over(event:MouseEvent):void
{
event.target.gotoAndPlay("Over");
}
function out(event:MouseEvent):void
{
event.target.gotoAndPlay("Out");
}
// detect fullscreen mode status and perform operations/adjustments
function fullScreenRedraw(event:FullScreenEvent):void
{
if (event.fullScreen) // full screen setup
{
// remove all the thumbnail listeners
thumb_mc.visible = false;
thumb_mc.removeEventListener(MouseEvent.CLICK, enterFullScreen);
thumb_mc.removeEventListener(MouseEvent.ROLL_OVER, over);
thumb_mc.removeEventListener(MouseEvent.ROLL_OUT, out);
// add all the exit button listeners
exit_mc.visible = true;
exit_mc.buttonMode = true;
exit_mc.addEventListener(MouseEvent.CLICK, exitFullScreen);
exit_mc.addEventListener(MouseEvent.ROLL_OVER, over);
exit_mc.addEventListener(MouseEvent.ROLL_OUT, out);
exit_mc.x = stageWidthAdjustment + (screenWidth/2) - exit_mc.width - screenMargin;
exit_mc.y = stageHeightAdjustment - (screenHeight/2) + screenMargin;
// load external sample content into container and position screen-centered
contentLoader.load(contentRequest);
addChild(contentLoader);
contentLoader.x = stageWidthAdjustment - (sampleWidth/2);
contentLoader.y = stageHeightAdjustment - (sampleHeight/2);
}
else // normal screen setup
{
SoundMixer.stopAll(); // stops the annoying audio that keeps running even after removing the child
removeChild(contentLoader); // Problem area??
contentLoader.unload(); // not sure if even need this
// add all the thumbnail listeners
thumb_mc.visible = true;
thumb_mc.gotoAndPlay("Out");
thumb_mc.buttonMode = true;
thumb_mc.addEventListener(MouseEvent.CLICK, enterFullScreen);
thumb_mc.addEventListener(MouseEvent.ROLL_OVER, over);
thumb_mc.addEventListener(MouseEvent.ROLL_OUT, out);
// remove all the exit button listeners
exit_mc.visible = false;
exit_mc.removeEventListener(MouseEvent.CLICK, exitFullScreen);
exit_mc.removeEventListener(MouseEvent.ROLL_OVER, over);
exit_mc.removeEventListener(MouseEvent.ROLL_OUT, out);
}
}


