1 Reply Latest reply on Mar 18, 2013 3:12 PM by Marissa2742485

    Flash Output Error

    Marissa2742485

      Hello I recently added this problem to a old Discussion in the comments but I am not sure it was the best place for it.

      I've been trying to add audio to my Flash. Everything is running smoothly except when I click on a muteToggle and playPauseToggle button that are both placed on my stage. I have instance names for both of them. These are the Errors I get in my Output.

       

      TypeError: Error #1009: Cannot access a property or method of a null object reference.

                at info.mixnwithmarissa.cakecreater::Main/togglePlayPause()[/Users/stude nt/Desktop/MM461_Lab3_mpollocktest1/info/mixnwithmarissa/cakecreater/M ain.as:153]

       

      TypeError: Error #1009: Cannot access a property or method of a null object reference.

                at info.mixnwithmarissa.cakecreater::Main/toggleMute()[/Users/student/De sktop/MM461_Lab3_mpollocktest1/info/mixnwithmarissa/cakecreater/Main.a s:138]

       

      Also here is my code in my main.as

       

      package info.mixnwithmarissa.cakecreater

      {

       

       

                import flash.display.MovieClip;

                import flash.events.Event;

                import flash.events.MouseEvent;

                import flash.net.navigateToURL;

                import flash.sampler.StackFrame;

                import flash.net.URLRequest;

                import flash.net.URLLoader;

                import flash.events.IOErrorEvent;

                import flash.events.ProgressEvent;

                import flash.display.Loader;

                import flash.media.Sound;

                import flash.media.SoundChannel;

                import flash.media.SoundLoaderContext;

                import flash.media.SoundTransform;

                /*added*/

       

       

       

       

                public class Main extends MovieClip

                {

       

                          private var musicPaused:Boolean = false;

                          private var musicMuted:Boolean = false;

                          private var musicPosition:Number = 0;

                          private var musicControls:MovieClip;

       

                          private var musicTrans:SoundTransform = new SoundTransform();

       

       

                          private var intro:MovieClip;

                          private var startt:MovieClip;

                          private var setting:MovieClip;

                          //private var game:MovieClip;

                          private var currentState:String;

       

       

                          private var xmlURL:URLRequest;

                          private var xmlLdr:URLLoader;

       

       

                          private var imgURL:URLRequest;

                          private var imgLdr:Loader;

       

                          private var swfURL:URLRequest;

                          private var swfLdr:Loader;

                          private var loaderDisplay:MovieClip;

                          private var transitionSound:Sound;

                          public var themeSound:Sound;

                          private var themeSoundURL:URLRequest;

                          public var themeChnl:SoundChannel;

                          public var themeLoaderContext:SoundLoaderContext;

                          public var xmlObj:XML;

                          public  var globalVol:Number = 1;

                          private var main:MovieClip;

       

       

       

       

                          public function Main()

                          {

       

       

                                    xmlURL = new URLRequest("xml/Appxml.xml");

                                    xmlLdr = new URLLoader();

       

       

                                    xmlLdr.addEventListener(Event.COMPLETE,onXMLLoaded);

                                    xmlLdr.addEventListener(IOErrorEvent.IO_ERROR,onIOErro r);

                                    xmlLdr.load(xmlURL);

       

                                    muteToggle.addEventListener(MouseEvent.CLICK, toggleMute);

                                    playPauseToggle.addEventListener(MouseEvent.CLICK, togglePlayPause);

       

       

                          }

       

                          private function onXMLLoaded(evt:Event):void

                          {

       

       

                                    xmlObj = new XML(xmlLdr.data);

       

       

                                    trace(xmlObj);

       

       

                                    //trace(mainXML.theme.music.@src);

       

       

                                    //trace("background image: "+mainXML.theme.@bg);

                                    //trace("theme music: "+mainXML.theme.@music);

                                    imgURL = new URLRequest(xmlObj.intro.theme.@bg);

                                    imgLdr = new Loader();

                                    //Note: Loader objects are display objects, so they must be added to the display list

                                    addChild(imgLdr);

                                    imgLdr.contentLoaderInfo.addEventListener(Event.COMPLE TE,onImgLoaded);

       

       

       

                                    intro = new Intro();

                                    this.addChild(intro);

       

       

                                    currentState = "intro";

       

                                    themeSoundURL = new URLRequest(xmlObj.intro.theme.@music);

                                    trace("music path: "+xmlObj.intro.theme.@music);

                                    themeSound = new Sound();

                                    themeLoaderContext = new SoundLoaderContext(3000, false);

                                    themeSound.addEventListener(Event.COMPLETE,soundLoaded );

                                    themeChnl = new SoundChannel();

                                    themeSound.load(themeSoundURL, themeLoaderContext);

                                    themeChnl = themeSound.play();

                                    /*var snd:Sound = new Sound();

                                    var context:SoundLoaderContext = new SoundLoaderContext(5000);

                                    var  req:URLLoaderRequest = new URLLoader*/

                          }

       

                          private function soundLoaded(evt:Event):void{

                                    trace("Sound Loaded!");

       

                          }

       

       

       

                private function onImgLoaded(evt:Event):void

                {

                          //trace("Image loaded!");

       

       

                          imgLdr.x = 20;

                          imgLdr.y = 20;

                          imgLdr.width = 200;

       

       

       

       

                          var origW:Number = imgLdr.contentLoaderInfo.width;

                          var origH:Number = imgLdr.contentLoaderInfo.height;

                          var newHeight:Number = origH * 200 / origW;

       

       

                          imgLdr.height = newHeight;

       

       

       

       

                          imgLdr.y = stage.stageHeight / 2 - imgLdr.height / 2;

       

       

                }

       

                private function toggleMute(evt:MouseEvent):void{

                                    if (!musicMuted){

                                              musicTrans.volume = 0;

                                              main.globalVol = 0;

                                              main.themeChnl.soundTransform = musicTrans;

                                              muteToggle.gotoAndStop(2);

                                              musicMuted = true;

       

                                    }else{

                                              musicTrans.volume = 1;

                                              main.themeChnl.soundTransform = musicTrans;

                                              muteToggle.gotoAndStop(1);

                                              musicMuted = false;

                          }

                }

       

                          private function togglePlayPause(evt:MouseEvent):void{

                                    if (!musicPaused){

                                              main.themeChnl.stop();

                                              musicPaused = true;

                                              playPauseToggle.gotoAndStop(2);

                                    }else{

                                              main.themeChnl = main.themeSound.play(musicPosition);

                                              musicPaused = false;

                                              playPauseToggle.gotoAndStop(1);

                                    }

                          }

       

       

       

                private function onIOError(evt:IOErrorEvent):void

                {

                          trace("XML loading error!!!");

                }

       

       

                public function changeState(newState:String):void

                {

       

       

       

       

                          switch (currentState)

                          {

                                    case "intro" :

                                              removeChild(intro);

                                              break;

                                    case "start" :

                                              removeChild(startt);

                                              break;

       

       

                                    case "setting" :

                                              removeChild(setting);

                                              break;

       

       

                                              //case "game":

                                              //game = new Game();

                                              //removeChild(game);

                                              //break;

       

       

       

       

                          }

       

       

                          switch (newState)

                          {

                                    case "intro" :

                                              intro = new Intro();

                                              addChild(intro);

                                              break;

       

       

                                    case "start" :

                                              startt = new Startt();

                                              addChild(startt);

                                              break;

       

       

                                    case "setting" :

                                              setting = new Setting();

                                              addChild(setting);

                                              break;

       

       

                                              //case "game":

                                              //game = new Game();

                                              //addChild(game);

                                              //break;

       

       

                          }

                          currentState = newState;

                          //now play transition sound recently added!

                          transitionSound = new ButtonSound();

                          transitionSound.play();

                }

      }

      }

      Here is a screenshot of my fla

      Screen Shot 2013-03-18 at 5.34.30 PM.png