4 Replies Latest reply: Mar 18, 2013 2:37 PM by Marissa2742485 RSS

    Output Errors

    Marissa2742485

      I am hoping someone can help me. I am getting these errors except eveything seems to be defined. Please let me know if I overlooked something or what I am doing wrong thankyou.

       

       

       

      Code

       

      package info.mixnwithmarissa.cakecreater {

       

                import flash.display.MovieClip;

                import flash.events.Event;

                import flash.events.MouseEvent;

                import flash.net.URLRequest;

                import flash.net.URLLoader;

                import flash.events.IOErrorEvent;

                import flash.events.ProgressEvent;

                import flash.display.Loader;

                public class Main extends MovieClip {

       

                          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;

                          public var xmlObj:XML;

                          private var loaderDisplay:MovieClip;

       

                          public var mainXML:XML;

       

       

       

                                    public function Main() {

       

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

                                    xmlLdr = new URLLoader();

       

                                    xmlLdr.addEventListener(Event.COMPLETE,onXMLLoaded);

                                    xmlLdr.addEventListener(IOErrorEvent.IO_ERROR,onIOError);

       

                                    xmlLdr.load(xmlURL);

                                    }

                                    private function onXMLLoaded(evt:Event):void{

       

                                    mainXML = new XML( xmlLdr.data);

       

                                    //trace(mainXML);

                                    //E4X (ECMA for XML) uses dot syntax to "drill down" to child elements and the @ to access attribute data, and [] to access by element index.

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

       

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

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

                                                imgURL = new URLRequest(mainXML.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.COMPLETE,onImgLoaded);

                                                imgLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onImgLoadProgress);

                                                imgLdr.load(imgURL);

                                                loaderDisplay = new ProgBar();

                                                addChild(loaderDisplay);

                                                //position

                                                loaderDisplay.x = 120;

                                                loaderDisplay.y = 200;

                                               

                                                swfURL = new URLRequest(xmlObj.theme.@anim);

                                                swfLdr = new Loader();

                                                //could add below existing onjects to apear beneath them

                                                addChildAt(swfLdr,0);

                                                swfLdr.load(swfURL);

       

                                    intro = new Intro();

                                    this.addChild(intro);

       

       

                                    currentState = "intro";

                             }

                            

                             private function onImgLoadProgress(evt:ProgressEvent):void{

                                    //trace("Load progress!");

                                    //trace(imgLdr.contentLoaderInfo.bytesLoaded);

                                    var loaded:Number = imgLdr.contentLoaderInfo.bytesLoaded;

                                    var total:Number = imgLdr.contentLoaderInfo.bytesTotal;

                                    var percent:Number = Math.round(loaded/total*100);

                                    loaderDisplay.percentField.text = percent;

                                    loaderDisplay.gotoAndStop(percent);

                                    loaderDisplay.gotoAndStop(percent);

                                    //trace("Percent Loaded = "(Math.round(loaded/total*100))+"%");

                          }

       

                          private function onImgLoaded(evt:Event):void{

                                    //trace("Image loaded!");

       

                                    removeChild(loaderDisplay);

       

                                    imgLdr.x = 20;

                                    imgLdr.y = 20;

                                    imgLdr.width = 200;

       

                                    //solve for new height maintaining aspect ration (so it doesn't look streched)

                                    var origW:Number = imgLdr.contentLoaderInfo.width;

                                    var origH:Number = imgLdr.contentLoaderInfo.height;

                                    var newHeight:Number = origH*200/origW;

       

                                    imgLdr.height= newHeight;

       

                                    //could centre it too

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

       

       

                            

                          }

       

                                    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;

                          }

                }

      }

       

       

       

       

       

       

      Output Errors

       

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

                at info.mixnwithmarissa.cakecreater::Main/onXMLLoaded()

                at flash.events::EventDispatcher/dispatchEventFunction()

                at flash.events::EventDispatcher/dispatchEvent()

                at flash.net::URLLoader/onComplete()

      TypeError: Error #1010: A term is undefined and has no properties.

                at info.mixnwithmarissa.cakecreater::Main/onImgLoadProgress()

      TypeError: Error #1010: A term is undefined and has no properties.

                at info.mixnwithmarissa.cakecreater::Main/onImgLoadProgress()

      TypeError: Error #1010: A term is undefined and has no properties.

                at info.mixnwithmarissa.cakecreater::Main/onImgLoadProgress()

        • 1. Re: Output Errors
          Nabren Community Member

          I am surprised you are not getting line numbers. Are you not running a debug build?

          • 2. Re: Output Errors
            Marissa2742485 Community Member

            No sorry I wasn't but I figured out the problem I was having. A text field was set to tlf text by mistake and then from there I figured out everything else. But thank you for your time.

            • 3. Re: Output Errors
              Marissa2742485 Community Member

              Actually you see, I am working on a new version of this at the moment. I've been trying to add audio to it. 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/student/Desktop/MM461_Lab 3_mpollocktest1/info/mixnwithmarissa/cakecreater/Main.as:153]

               

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

                        at info.mixnwithmarissa.cakecreater::Main/toggleMute()[/Users/student/Desktop/MM461_Lab3_mpo llocktest1/info/mixnwithmarissa/cakecreater/Main.as: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,onIOError);

                                            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.COMPLETE,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();

                        }

              }

              }

              • 4. Re: Output Errors
                Marissa2742485 Community Member

                Here is a screen shot of my fla

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