|
metadata
when i add a preloader, my game is no longer playable :( my “play” button is not clickable. also, the difficulty level buttons (“easy” and “hard”), which are not supposed to appear on the stage until the player clicks on “play,” are visible and not clickable either.
any ideas why? This is the error I get:
TypeError: Error #1009: Cannot access a property or method of a null object reference. at Game/loading()[Game::frame1:10]
This is the AS3 for my preloader, which works fine when I use it with other fla files:
stop();
this.addEventListener(Event.ENTER\_FRAME, loading);
function loading(e:Event):void {
var total:Number = this.stage.loaderInfo.bytesTotal; var loaded:Number = this.stage.loaderInfo.bytesLoaded; I ADDED THESE LINESvar totalAdjFrameNum = (Math.floor(((loaded/total)\*100)/10))+1; preloader\_mc.gotoAndStop(“2”) loader\_txt.text = Math.floor((loaded/total)\*100)+ “%”; if (total == loaded) { play(); this.removeEventListener(Event.ENTER\_FRAME, loading); }
}
The error points to the “playNowButton.visible = true;” line in the following code:
package
{
import flash.display.\*
import flash.text.\*
import flash.events.\*
import flash.net.URLRequest;
public class Game extends MovieClip
{
static public var main;
…
public var difficultyMode:String;
static public var NORMAL:String = “Normal”;
static public var HARD:String = “Hard”;
…
public function Game()
{
main = this;
playNowButton.visible = true;
normalButton.visible = false;
hardButton.visible = false;
….
thank you for your help!
|
|
metadata
post this in the PROGRAMMING section, two sections below this one
hope it helps!
|
|
metadata
> *Originally posted by **[ninjabytestudios](/forums/11/topics/103242?page=1#posts-2267730):***
>
> post this in the PROGRAMMING section, two sections below this one
>
> hope it helps!
This is not a program, but a game….
|
|
metadata
> *Originally posted by **[sr2449](/forums/11/topics/103242?page=1#posts-3354872):***
> > *Originally posted by **[ninjabytestudios](/forums/11/topics/103242?page=1#posts-2267730):***
> >
> > post this in the PROGRAMMING section, two sections below this one
> >
> > hope it helps!
>
> This is not a program, but a game….
Haha, what do you think games are made of, silly?
Anyways, I was having this problem a couple of days ago. When something is NULL, there is nothing there in terms of value. So, you must give the variable causing problems a value. Try tracing your variables and see what they return(I recommend starting with playNowButton since you tried using a method of it when it isn’t given an instance name.) If it’s null, make it…..not null!
|