|
-
what the heck is with this error!?
I don't know if I'm just tired here or what. But I can't understand why this isnt working. It prints out all the correct traces from the onGameLoaderProgress function up to 1. then it gives my a TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.scargames::Main$iinit() error.
Code:
package org.*****.kylemcknight
{
/**
* ...
* @author DefaultUser (Tools -> Custom Arguments...)
*/
import flash.display.Loader;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
public class Main extends MovieClip
{
/*STAGE VARS*/
public var playGameBtn:SimpleButton;
/*INSTANCE VARS*/
private var _gameLoaded:Boolean;
private var _gameLoader:Loader;
private var _urlRequest:URLRequest;
public function Main() {
init();
}
private function init():void {
playGameBtn.addEventListener(MouseEvent.CLICK, onPlayGameBtnClicked);
}
public function onPlayGameBtnClicked(e:MouseEvent):void {
trace(e.target);
_urlRequest = new URLRequest("../../dist/Raccoon Valley.swf");
_gameLoader = new Loader();
_gameLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onGameLoaderComplete);
_gameLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onGameLoaderProgress);
_gameLoader.load(_urlRequest);
}
public function onGameLoaderComplete(e:Event):void {
trace("onGameLoaderComplete");
this.gameLoaded = true;
}
public function onGameLoaderProgress(e:ProgressEvent):void {
trace("onGameLoaderProgress: " + (e.bytesLoaded / e.bytesTotal));
}
public function get gameLoaded():Boolean {
return _gameLoaded;
}
public function set gameLoaded(val:Boolean):void {
_gameLoaded = val;
}
}
}
Thanks for any help!
Kyle
-
Hi,
Believe it or not, they try to keep it a secret, but flash can actually tell you what line the error occurs on. I don't know if you've tried already, but ctrl-shift-enter, enters debug mode, it gives you the line that is the problem.
The problem, obviously, is to do with you trying to play with something that isn't on the stage, or doesn't exist.
-
I hate the flash debugger! haha. But I did figure out the problem. It wasn't in the class I posted, it was in the document class of the loaded swf. I was accessing the stage var in it before it was actually added to the stage
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|