0 Replies Latest reply on Jan 22, 2010 9:06 AM by Chipleh

    2 part question - loading and key detection...

    Chipleh Level 3

      Hi,

       

      I have an issue with a function. I have been developing my first AS3 application and everything was running smoothly until I added a second frame. I had this code on frame 1, which was working perfectly:

       

      function keyDetection() {
      stage.addEventListener(KeyboardEvent.KEY_DOWN, showRevisionWindow);
      }

      function showRevisionWindow(keyEvent:KeyboardEvent) {
      var modifier:String="";
        var keyPressed:String="";

        keyPressed=keyEvent.keyCode.toString();  
      if(keyEvent.ctrlKey && keyEvent.keyCode == 192){
        if (revisionAuthorWindow.visible == false){
           revisionAuthorWindow.visible = true;
         revisionAuthorWindow.x = 256;
         revisionAuthorWindow.y = 192;
          }else{
           revisionAuthorWindow.x = -300;
             revisionAuthorWindow.y = -300;
             revisionAuthorWindow.visible = false;
          }
         }
      }

      keyDetection();

       

      I moved the code to frame 2, added a loader function to frame 1, and now when I enter frame 2, I recieve this message:

       

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at SIMmersion_frontEnd_prototype_menu02_loadingTest_fla::MainTimeline/keyDetection()
      at SIMmersion_frontEnd_prototype_menu02_loadingTest_fla::MainTimeline/SIMmersion_frontEnd_pr ototype_menu02_loadingTest_fla::frame2()

       

      However, if I move this code back to frame 1, or comment out my loader function on frame 1 and go directly to frame 2, I will not receive the error.

       

      Here is the loader code I am currently using on frame 1, while the code above is currently on frame 2:

       

      stop();

      var loader : Loader = new Loader(); 
          var request : URLRequest = new URLRequest("myFile.swf"); 
          loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, updateProgress);
          loader.load(request);

      function updateProgress(event : ProgressEvent) : void
      {
          var pI  = event.bytesLoaded/event.bytesTotal*100;
      trace ("pI = " + pI + "%");
      preLoader.pLoader.width = pI*5 ;

      var pI_int:int  = event.bytesLoaded/event.bytesTotal*100;
      preLoader.pIInt.text = "Loaded: " + pI_int + "%";
      if (pI_int==100){
        preLoader.visible = false;
        gotoAndStop(2);
      }else{
        preLoader.visible = true;
        gotoAndStop(1);
      }
      }

       

      If anyone could shed some light on why this happening, I would be very appreciative.

       

      Also, how do you use a URLRequest to reference 'itself'. Instead of using "myFile.swf", I want to reference the Flash file itself without having to indicate a name of the Flash file to load. is that possible?

       

          var request : URLRequest = new URLRequest("myFile.swf");

       

      something along the lines of:

       

          var request : URLRequest = new URLRequest(this);

       

      Thanks in advance; I know this is a long-winded question.

       

      Cheers,

      ~Chip