Skip to main content
Inspiring
March 9, 2021
Question

1009 enter frame

  • March 9, 2021
  • 1 reply
  • 290 views

 

Hello. I need help. My code works fine, but when I change the scene with the MC "pruebadef", I get error # 1009

 

It is the enter_frame event that is not working well. This is the error:

TypeError: Error # 1009: Cannot access a property or method of a null object reference.
at baroqueimprovisation_fla :: MainTimeline / fl_ClickToGoToScene_24 () [baroqueimprovisation_fla.MainTimeline :: frame6: 54

 

this is the code.

 

 

stop();

import componentes.ClaseMenu;
import flash.events.MouseEvent;
import flash.media.SoundMixer;
import componentes.MP3Pitch;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.events.Event;
import flash.media.Sound;
import flash.utils.Timer;
import flash.events.TimerEvent;

//variables
var menuItalian:ClaseMenu = new ClaseMenu (barritasMenu, panel, tapa);

var violaItalian1:MP3Pitch = new MP3Pitch ();
	violaItalian1.rate += 0.0;
	var violaSoundItalian1:Sound = new Sound();
	violaSoundItalian1 = violaItalian1._sound;
	violaItalian1._req = new URLRequest ("musica/italian/viola.mp3");
	var trans:SoundTransform = new SoundTransform(0.5);
	var myChannel:SoundChannel = new SoundChannel();
	violaSoundItalian1.load(violaItalian1._req);

var tiorbaItalian1:MP3Pitch = new MP3Pitch ();
	tiorbaItalian1.rate += 0.0;
	var tiorbaSoundItalian1:Sound = new Sound();
	tiorbaSoundItalian1 = tiorbaItalian1._sound;
	tiorbaItalian1._req = new URLRequest ("musica/italian/tiorba.mp3");
	var trans2:SoundTransform = new SoundTransform(0.5);
	var myChannel2:SoundChannel = new SoundChannel();
	tiorbaSoundItalian1.load(tiorbaItalian1._req);

var claveItalian1:MP3Pitch = new MP3Pitch ();
	claveItalian1.rate += 0.0;
	var claveSoundItalian1:Sound = new Sound();
	claveSoundItalian1 = claveItalian1._sound;
	claveItalian1._req = new URLRequest ("musica/italian/clave.mp3");
	var trans3:SoundTransform = new SoundTransform(0.5);
	var myChannel3:SoundChannel = new SoundChannel();
	claveSoundItalian1.load(claveItalian1._req);

var timer:Timer = new Timer (12800);
//funciones
function musicLoaded (event:Event):void{
playStop.addEventListener (Event.ENTER_FRAME, botonPlayStop);
aumentar.enabled = false;
disminuir.enabled = false;
	}

function fl_ClickToGoToScene_24(event:MouseEvent):void{
	MovieClip(this.root).gotoAndPlay(1, "Controladores");
	playStop.removeEventListener (Event.ENTER_FRAME, botonPlayStop);
	SoundMixer.stopAll();
}
	

function botonPlayStop (event:Event):void{
	if (violaItalian.currentLabel == "uno" && tiorbaItalian.currentLabel == "uno" && claveItalian.currentLabel == "uno"){
		playStop.gotoAndStop(2);
		playStop.removeEventListener (MouseEvent.CLICK, playStopMusic);
		SoundMixer.stopAll();
		}
	else{
		playStop.gotoAndStop(1);
		playStop.addEventListener (MouseEvent.CLICK, playStopMusic);
		}
	}	
	
function playStopMusic (event:MouseEvent):void{

	if 	(playStop.currentLabel == "dos"){
		playStop.gotoAndStop(1);
		aumentar.enabled = false;
		disminuir.enabled = false
		aumentar.removeEventListener (MouseEvent.CLICK, onTransformMas);
		disminuir.removeEventListener (MouseEvent.CLICK, onTransformMenos);
		aumentar.removeEventListener (MouseEvent.CLICK, enabledButtonMas);
		disminuir.removeEventListener (MouseEvent.CLICK, enabledButtonMenos);
		SoundMixer.stopAll();
		playStop.addEventListener (Event.ENTER_FRAME, botonPlayStop);
		timer.stop();
		}
		
	else if (violaItalian.currentLabel == "dos" && tiorbaItalian.currentLabel == "dos" && claveItalian.currentLabel == "dos"){
		playStop.gotoAndStop(2);
		aumentar.enabled = true;
		disminuir.enabled = true;
		aumentar.addEventListener (MouseEvent.CLICK, onTransformMas);
		disminuir.addEventListener (MouseEvent.CLICK, onTransformMenos);
		aumentar.addEventListener (MouseEvent.CLICK, enabledButtonMas);
		disminuir.addEventListener (MouseEvent.CLICK, enabledButtonMenos);
		playStop.removeEventListener (Event.ENTER_FRAME, botonPlayStop);
		timer.start();
		timer.addEventListener(TimerEvent.TIMER, timerListener);
		myChannel = violaSoundItalian1.play (0,1,trans);
		myChannel2 = tiorbaSoundItalian1.play (0,1,trans2);
		myChannel3 = claveSoundItalian1.play (0,1,trans3);
		}
		
	else if (violaItalian.currentLabel == "dos" && tiorbaItalian.currentLabel == "dos"){
		playStop.gotoAndStop(2);
		aumentar.enabled = true;
		disminuir.enabled = true;
		aumentar.addEventListener (MouseEvent.CLICK, onTransformMas);
		disminuir.addEventListener (MouseEvent.CLICK, onTransformMenos);
		aumentar.addEventListener (MouseEvent.CLICK, enabledButtonMas);
		disminuir.addEventListener (MouseEvent.CLICK, enabledButtonMenos);
		playStop.removeEventListener (Event.ENTER_FRAME, botonPlayStop);
		timer.start();
		timer.addEventListener(TimerEvent.TIMER, timerListener);
		myChannel = violaSoundItalian1.play (0,1,trans);
		myChannel2 = tiorbaSoundItalian1.play (0,1,trans2);
		}
		
	else if (violaItalian.currentLabel == "dos" && claveItalian.currentLabel == "dos"){
		playStop.gotoAndStop(2);
		aumentar.enabled = true;
		disminuir.enabled = true;
		aumentar.addEventListener (MouseEvent.CLICK, onTransformMas);
		disminuir.addEventListener (MouseEvent.CLICK, onTransformMenos);
		aumentar.addEventListener (MouseEvent.CLICK, enabledButtonMas);
		disminuir.addEventListener (MouseEvent.CLICK, enabledButtonMenos);
		playStop.removeEventListener (Event.ENTER_FRAME, botonPlayStop);
		timer.start();
		timer.addEventListener(TimerEvent.TIMER, timerListener);
		myChannel = violaSoundItalian1.play (0,1,trans);
		myChannel3 = claveSoundItalian1.play (0,1,trans3);
		}
		
	else if (tiorbaItalian.currentLabel == "dos" && claveItalian.currentLabel == "dos"){
		playStop.gotoAndStop(2);
		aumentar.enabled = true;
		disminuir.enabled = true;
		aumentar.addEventListener (MouseEvent.CLICK, onTransformMas);
		disminuir.addEventListener (MouseEvent.CLICK, onTransformMenos);
		aumentar.addEventListener (MouseEvent.CLICK, enabledButtonMas);
		disminuir.addEventListener (MouseEvent.CLICK, enabledButtonMenos);
		playStop.removeEventListener (Event.ENTER_FRAME, botonPlayStop);
		timer.start();
		timer.addEventListener(TimerEvent.TIMER, timerListener);
		myChannel2 = tiorbaSoundItalian1.play (0,1,trans2);
		myChannel3 = claveSoundItalian1.play (0,1,trans3);
		}
		
	else if (violaItalian.currentLabel == "dos"){
		playStop.gotoAndStop(2);
		aumentar.enabled = true;
		disminuir.enabled = true;
		aumentar.addEventListener (MouseEvent.CLICK, onTransformMas);
		disminuir.addEventListener (MouseEvent.CLICK, onTransformMenos);
		aumentar.addEventListener (MouseEvent.CLICK, enabledButtonMas);
		disminuir.addEventListener (MouseEvent.CLICK, enabledButtonMenos);
		playStop.removeEventListener (Event.ENTER_FRAME, botonPlayStop);
		timer.start();
		timer.addEventListener(TimerEvent.TIMER, timerListener);
		myChannel = violaSoundItalian1.play (0,1,trans);
		}
		
	else if (tiorbaItalian.currentLabel == "dos"){
		playStop.gotoAndStop(2);
		aumentar.enabled = true;
		disminuir.enabled = true;
		aumentar.addEventListener (MouseEvent.CLICK, onTransformMas);
		disminuir.addEventListener (MouseEvent.CLICK, onTransformMenos);
		aumentar.addEventListener (MouseEvent.CLICK, enabledButtonMas);
		disminuir.addEventListener (MouseEvent.CLICK, enabledButtonMenos);
		playStop.removeEventListener (Event.ENTER_FRAME, botonPlayStop);
		timer.start();
		timer.addEventListener(TimerEvent.TIMER, timerListener);
		myChannel2 = tiorbaSoundItalian1.play (0,1,trans2);
		}

	else if (claveItalian.currentLabel == "dos"){
		playStop.gotoAndStop(2);
		aumentar.enabled = true;
		disminuir.enabled = true;
		aumentar.addEventListener (MouseEvent.CLICK, onTransformMas);
		disminuir.addEventListener (MouseEvent.CLICK, onTransformMenos);
		aumentar.addEventListener (MouseEvent.CLICK, enabledButtonMas);
		disminuir.addEventListener (MouseEvent.CLICK, enabledButtonMenos);
		playStop.removeEventListener (Event.ENTER_FRAME, botonPlayStop);
		timer.start();
		timer.addEventListener(TimerEvent.TIMER, timerListener);
		myChannel3 = claveSoundItalian1.play (0,1,trans3);
		}
	}
	
function timerListener (e:TimerEvent):void{
	playStop.gotoAndStop(1);
	aumentar.enabled = false;
	disminuir.enabled = false;
	aumentar.removeEventListener (MouseEvent.CLICK, enabledButtonMas);
	disminuir.removeEventListener (MouseEvent.CLICK, enabledButtonMenos);
}

function onTransformMas (event:MouseEvent): void{
		trans.volume +=0.1;
		myChannel.soundTransform = trans;
		trans2.volume +=0.1;
		myChannel2.soundTransform = trans2;
		trans3.volume +=0.1;
		myChannel3.soundTransform = trans3;
		disminuir.addEventListener (MouseEvent.CLICK, onTransformMenos);
	}

function onTransformMenos (event:MouseEvent): void{
	if (trans.volume >= 0.1 || trans2.volume >= 0.1 || trans3.volume >= 0.1){
		trans.volume -=0.1;
		myChannel.soundTransform = trans;
		trans2.volume -=0.1;
		myChannel2.soundTransform = trans2;
		trans3.volume -=0.1;
		myChannel3.soundTransform = trans3;
		}
		
	else if (trans.volume == 0 || trans2.volume == 0 || trans3.volume == 0){
		disminuir.removeEventListener (MouseEvent.CLICK, onTransformMenos);
		}
	}

function enabledButtonMas (event:MouseEvent):void{
	if (trans.volume > 0.9 || trans2.volume > 0.9 || trans3.volume > 0.9){
		aumentar.enabled = false;
		}
		
	else{
		aumentar.enabled = true;
		}
	}

function enabledButtonMenos (event:MouseEvent):void{
	if (trans.volume < 0.1 || trans2.volume < 0.1 || trans3.volume < 0.1){
		disminuir.enabled = false;
		}
		
	else{
		disminuir.enabled = true;
		}
	}
	
//listeners
claveSoundItalian1.addEventListener(Event.COMPLETE, musicLoaded);
pruebadef.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_24);
//estados iniciales
playStop.gotoAndStop(2);

 

 

This is the area where the error occurs (6:54)- Basically, I change the scene and remove the enterframe listener and other methods

 

52 function fl_ClickToGoToScene_24(event:MouseEvent):void{
53 MovieClip(this.root).gotoAndPlay(1, "Controladores");
54 playStop.removeEventListener (Event.ENTER_FRAME, botonPlayStop);
55 SoundMixer.stopAll();
56}

 

The enter_frame event appears when a sound is loaded:

 

46 function musicLoaded (event:Event):void{
47 playStop.addEventListener (Event.ENTER_FRAME, botonPlayStop);
48 aumentar.enabled = false;
49 disminuir.enabled = false;
50 }

 

also appears in the playStopMusic function.aparec Once

 

thanks!!

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    March 10, 2021

    does playStop exist on frame 6?

     

    if you think it does, confirm by using:

     

    52 function fl_ClickToGoToScene_24(event:MouseEvent):void{
    53 MovieClip(this.root).gotoAndPlay(1, "Controladores");

    trace(playStop);
    54 playStop.removeEventListener (Event.ENTER_FRAME, botonPlayStop);
    55 SoundMixer.stopAll();
    56}

    Inspiring
    March 13, 2021

    Finally, I am not using the enter_frame in my project, so I close this doubt. Thanks!!

    kglad
    Community Expert
    Community Expert
    March 13, 2021

    you're welcome.