I'm making a simple game in Adobe Flash CS4 using ActionScript 3. I recently implemented a new, very small preloader to replace the placeholder that I was using. However, once I did this, I seemed to break everything.
The first frame has only a stop();
in "Actions" and then a DocumentClass external class file (all of my classes are external) that sets up the preloader, which is in its own class file. Once the preloader is done, it fires off an Event to the DocumentClass, which runs a gotoAndStop(3);
. On slide three is a movie clip titled Main, with its own class file.
Main imports a bunch of stuff, then loads the opening screen of the game. At this point everything basically breaks down. Any attempts to modify things that are on this opening screen (which has both a class file and MovieClip object) results in "TypeError: Error #1009: Cannot access a property or method of a null object reference." I thought this code might be running before the MovieClip is on the stage, so I added addEventListener( Event.ADDED_TO_STAGE, onAddtoStage );
and moved the code to an onAddtoStage
function; while doing trace("this is the stage: "+stage);
and trace("this is my parent: "+this.parent);
will return the proper, non-null values, I still can't modify anything (for example, making a MovieClip object I'd like to hide invisible by setting invisibleBG.alpha = 0;
still returns Error #1009).
Furthermore, while the Main MovieClip is visible on the stage, the opening screen MovieClip doesn't show up. I'm not sure if it's behind the Main object somehow, but it seems like it's simply not on the stage at all.
There's some of my code below. I can add more if this doesn't show what the problem is. I've been really scratching my head over this; of course, it took me two days to figure out I couldn't modify a TextField
because it was stretched out over two frames, so there might be a very simple solution. Thanks in advance for your help!
Here's most of the class that handles the initial loading:
public class DocumentClass extends MovieClip
{
public var loadingScreen:LoadingScreen;
public function DocumentClass()
{
loadingScreen = new LoadingScreen();
addChild( loadingScreen );
stage.stageFocusRect = false;
loadingScreen.addEventListener( Event.COMPLETE, onPreloaderComplete );
loadingScreen.setLoaderInfo( loaderInfo );
}
public function onPreloaderComplete( e:Event ):void
{
loadingScreen.removeEventListener( Event.COMPLETE, onPreloaderComplete );
removeChild( loadingScreen );
loadingScreen = null;
gotoAndStop( 3 );
}
}
Here's the relevant portion of the Main class:
public class Main extends MovieClip
{
public function Main()
{
showDesktop();
}
public function showDesktop():void
{
desktopScreen = new DesktopScreen();
addChild( desktopScreen );
stage.focus = desktopScreen;
}
}
And the relevant portion of DesktopScreen, the game's opening screen:
public class DesktopScreen extends MovieClip
{
public function DesktopScreen()
{
addEventListener( Event.ADDED_TO_STAGE, onAddtoStage );
}
public function onAddtoStage( e:Event ):void
{
Mouse.show();
invisibleBG.alpha = 0;
fakeButton.stop();
time = new Time;
time.x = 504;
time.y = 3;
addChild( time );
}
}
TL;DR I'm adding a MovieClip to the stage, and even though I can tell via trace
functions that it thinks it's on the stage, I can't see it or modify any of it's contents in a way that would require it to actually be on the stage.
Main
on slide 3 of the stage timeline or on slide 3 of yourDocumentClass
? – FoggzieMain
is on slide 3 of the stage timeline.Main
shows up (the MovieClip just contains a background) and runs code, but DesktopScreen runs code but does not show up. Hope that helps clear things up. – steve richey