3 Replies - 1842 Views - Last Post: 02 July 2011 - 03:01 PM

#1 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 247
  • Joined: 29-November 08

Named Instance on Stage has Null value in frame 2(AS3)

Posted 01 July 2011 - 12:34 PM

okay I've been working on this for quite some time now

I have three button symbols in frame 2: one with the instance name (for actionscript) btn_Aussie1, another one named btn_Aussie2, and a third named btn_Aussie3 each time I try to add an EventListener to one one of buttons I keep getting Cannot Access an object each time I enter frame 2 here's my code for frame's 1 & 2:

FRAME 1:
import flash.media.Sound;
stop();
var soundClip:Sound;
var soundChannel:SoundChannel = new SoundChannel();
function init():void {
	soundClip = new Sound();
	soundClip.load(new URLRequest(".\\Wheel of Fortune.mp3"));
	soundClip.addEventListener(Event.COMPLETE,soundLoaded);
}//end init()

init();

function soundLoaded(e:Event):void {
	soundChannel = soundClip.play();
}//end soundLoaded

//txtWheel.text = "";
//this.aussie_btn.addEventListener(MouseEvent.MOUSE_OVER,aussieMouseOver);
//this.aussie_btn.addEventListener(MouseEvent.MOUSE_OUT,aussieMouseOut);
this.aussie_btn.addEventListener(MouseEvent.ROLL_OVER,aussieMouseOver);
this.aussie_btn.addEventListener(MouseEvent.ROLL_OUT,aussieMouseOut);
this.aussie_btn.addEventListener(MouseEvent.CLICK,aussieClick);

//this.bigMoney_btn.addEventListener(MouseEvent.MOUSE_OVER,moneyMouseOver);
//this.bigMoney_btn.addEventListener(MouseEvent.MOUSE_OUT,moneyMouseOut);
this.bigMoney_btn.addEventListener(MouseEvent.ROLL_OVER,moneyMouseOver);
this.bigMoney_btn.addEventListener(MouseEvent.ROLL_OUT,moneyMouseOut);
this.bigMoney_btn.addEventListener(MouseEvent.CLICK,moneyClick);

//this.finland_btn.addEventListener(MouseEvent.MOUSE_OVER,finlandMouseOver);
//this.finland_btn.addEventListener(MouseEvent.MOUSE_OUT,finlandMouseOut);
this.finland_btn.addEventListener(MouseEvent.ROLL_OVER,finlandMouseOver);
this.finland_btn.addEventListener(MouseEvent.ROLL_OUT,finlandMouseOut);
this.finland_btn.addEventListener(MouseEvent.CLICK,finlandClick);


//this.gameboy_btn.addEventListener(MouseEvent.MOUSE_OVER,gameboyMouseOver);
//this.gameboy_btn.addEventListener(MouseEvent.MOUSE_OUT,gameboyMouseOut);
this.gameboy_btn.addEventListener(MouseEvent.ROLL_OVER,gameboyMouseOver);
this.gameboy_btn.addEventListener(MouseEvent.ROLL_OUT,gameboyMouseOut);
this.gameboy_btn.addEventListener(MouseEvent.CLICK,gameboyClick);

//this.nes_btn.addEventListener(MouseEvent.MOUSE_OVER,nesMouseOver);
//this.nes_btn.addEventListener(MouseEvent.MOUSE_OUT,nesMouseOut);
this.nes_btn.addEventListener(MouseEvent.ROLL_OVER,nesMouseOver);
this.nes_btn.addEventListener(MouseEvent.ROLL_OUT,nesMouseOut);
this.nes_btn.addEventListener(MouseEvent.CLICK,nesClick);

//this.phillipine_btn.addEventListener(MouseEvent.MOUSE_OVER,phillipneMouseOver);
//this.phillipine_btn.addEventListener(MouseEvent.MOUSE_OUT,phillipneMouseOut);
this.phillipine_btn.addEventListener(MouseEvent.ROLL_OVER,phillipneMouseOver);
this.phillipine_btn.addEventListener(MouseEvent.ROLL_OUT,phillipneMouseOut);
this.phillipine_btn.addEventListener(MouseEvent.CLICK,phillipneClick);

//this.french_btn.addEventListener(MouseEvent.MOUSE_OVER,frenchMouseOver);
//this.french_btn.addEventListener(MouseEvent.MOUSE_OUT,frenchMouseOut);
this.french_btn.addEventListener(MouseEvent.ROLL_OVER,frenchMouseOver);
this.french_btn.addEventListener(MouseEvent.ROLL_OUT,frenchMouseOut);
this.french_btn.addEventListener(MouseEvent.CLICK,frenchClick);

//this.turnTable_btn.addEventListener(MouseEvent.MOUSE_OVER,turntableMouseOver);
//this.turnTable_btn.addEventListener(MouseEvent.MOUSE_OUT,turntableMouseOut);
this.turnTable_btn.addEventListener(MouseEvent.ROLL_OVER,turntableMouseOver);
this.turnTable_btn.addEventListener(MouseEvent.ROLL_OUT,turntableMouseOut);
this.turnTable_btn.addEventListener(MouseEvent.CLICK,turntableClick);

//this.uk_btn.addEventListener(MouseEvent.MOUSE_OVER,ukMouseOver);
//this.uk_btn.addEventListener(MouseEvent.MOUSE_OUT,ukMouseOut);
this.uk_btn.addEventListener(MouseEvent.ROLL_OVER,ukMouseOver);
this.uk_btn.addEventListener(MouseEvent.ROLL_OUT,ukMouseOut);
this.uk_btn.addEventListener(MouseEvent.CLICK,ukClick);

function aussieMouseOver(e:MouseEvent):void {
	txt_Wheel.text = "Aussie Wheel";
}//end aussieMouseOver
function aussieMouseOut(e:MouseEvent):void {
	txt_Wheel.text = "";
}//endaussieMouseOut
function aussieClick(e:MouseEvent):void {
	soundChannel.stop();
	gotoAndStop("mnu_Aussie");
}//endAussieClick

function moneyMouseOver(e:MouseEvent):void {
	txt_Wheel.text = "Big Money Wheel";
}//end moneyMouseOver
function moneyMouseOut(e:MouseEvent):void {
	txt_Wheel.text = "";
}//end moneyMouseOut
function moneyClick(e:MouseEvent):void {
	soundChannel.stop();
	gotoAndStop("mnu_BigMoney");
}//end moneyClick

function finlandMouseOver(e:MouseEvent):void {
	txt_Wheel.text = "Finnish Wheel";
}//endfinlandMouseOver
function finlandMouseOut(e:MouseEvent):void {
	txt_Wheel.text = "";
}//end finlandMouseOut
function finlandClick(e:MouseEvent):void {
	soundChannel.stop();
	gotoAndStop("mnu_Finnish");
}

function gameboyMouseOver(e:MouseEvent):void {
	txt_Wheel.text = "Gameboy Wheel";
}
function gameboyMouseOut(e:MouseEvent):void {
	txt_Wheel.text = "";
}
function gameboyClick(e:MouseEvent):void {
	soundChannel.stop();
	gotoAndStop("mnu_Gameboy");
}

function nesMouseOver(e:MouseEvent):void {
	txt_Wheel.text = "NES Wheel";
}
function nesMouseOut(e:MouseEvent):void {
	txt_Wheel.text = "";
}
function nesClick (e:MouseEvent):void {
	soundChannel.stop();
	gotoAndStop("mnu_NES");
}

function phillipneMouseOver(e:MouseEvent):void {
	txt_Wheel.text = "Phillipno Wheel";
}
function phillipneMouseOut(e:MouseEvent):void {
	txt_Wheel.text = "";
}
function phillipneClick(e:MouseEvent):void {
	soundChannel.stop();
	gotoAndStop("mnu_Phillipno");
}

function frenchMouseOver(e:MouseEvent):void {
	txt_Wheel.text = "French Wheel";
}
function frenchMouseOut(e:MouseEvent):void {
	txt_Wheel.text = "";
}
function frenchClick(e:MouseEvent):void {
	soundChannel.stop();
	gotoAndStop("mnu_French");
}

function turntableMouseOver(e:MouseEvent):void {
	txt_Wheel.text = "US Wheel";
}
function turntableMouseOut(e:MouseEvent):void {
	txt_Wheel.text = "";
}
function turntableClick(e:MouseEvent):void {
	soundChannel.stop();
	gotoAndStop("mnu_US");
}

function ukMouseOver(e:MouseEvent):void {
	txt_Wheel.text = "UK Wheel";
}
function ukMouseOut(e:MouseEvent):void {
	txt_Wheel.text = "";
}
function ukClick(e:MouseEvent):void {
	soundChannel.stop();
	gotoAndStop("mnu_UK");
}



FRAME 2:
this.btn_Aussie1.addEventListener(MouseEvent.CLICK,aussie1Player);
this.btn_Aussie2.addEventListener(MouseEvent.CLICK,aussie2Player);
this.btn_Aussie3.addEventListener(MouseEvent.CLICK,aussie3Player);


function aussie1Player(e:MouseEvent):void {
	mnuAussieSoundChannel.stop();
	gotoAndStop("Aussie1Player");
}
function aussie2Player(e:MouseEvent):void {
	mnuAussieSoundChannel.stop();
	gotoAndStop("Aussie2Player");
}
function aussie3Player(e:MouseEvent):void {
	mnuAussieSoundChannel.stop();
	gotoAndStop("Aussie3Player");
}



from what I had heard I can access any object on the stage as soon as I enter the frame Was I told Wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: Named Instance on Stage has Null value in frame 2(AS3)

#2 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: Named Instance on Stage has Null value in frame 2(AS3)

Posted 01 July 2011 - 01:19 PM

1. Where is this code placed ? Timeline or in some external class ?

2. You are right, you can access any object as soon as the frame is drawn.

3. Try putting a stop() statement in frame-2. Might be the case that the frame is not stopping.

4. Still getting errors ? Copy-Paste the exact error you are getting.
Was This Post Helpful? 0
  • +
  • -

#3 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 247
  • Joined: 29-November 08

Re: Named Instance on Stage has Null value in frame 2(AS3)

Posted 01 July 2011 - 08:52 PM

I have added the stop, the code is on the main Timeline
here is the error
[SWF] C:\Users\Owner\Documents\WOFlash\Wheel.swf - 5597705 bytes after decompression
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at Wheel_fla::MainTimeline/frame2()[Wheel_fla.MainTimeline::frame2:16]
	at flash.display::MovieClip/gotoAndStop()
	at Wheel_fla::MainTimeline/aussieClick()[Wheel_fla.MainTimeline::frame1:81]


Was This Post Helpful? 0
  • +
  • -

#4 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: Named Instance on Stage has Null value in frame 2(AS3)

Posted 02 July 2011 - 03:01 PM

View PostBraber01, on 02 July 2011 - 09:22 AM, said:

I have added the stop, the code is on the main Timeline
here is the error
[SWF] C:\Users\Owner\Documents\WOFlash\Wheel.swf - 5597705 bytes after decompression
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at Wheel_fla::MainTimeline/frame2()[Wheel_fla.MainTimeline::frame2:16]
	at flash.display::MovieClip/gotoAndStop()
	at Wheel_fla::MainTimeline/aussieClick()[Wheel_fla.MainTimeline::frame1:81]



Well if you check the error given, you will know that the error occurs from the code on frame1 where you have the aussieClick() function. That is this code:

function aussieClick(e:MouseEvent):void {
    soundChannel.stop();
    gotoAndStop("mnu_Aussie");
}//endAussieClick


Things to check :

gotoAndStop("mnu_Aussie"); Do you really have a frame with that label. Check again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1