加载swf游戏同时刺激下载但不正常时出错

时间:2015-02-20 04:40:59

标签: actionscript-3 flash loader

好的,所以当我运行loader.swf时,它会加载我的game.swf完全没问题。但当我刺激下载时,正好是70%,我的game.swf音乐开始播放,并显示以下错误:

  

TypeError:错误#1009:无法访问空对象引用的属性或方法。     在GAME_fla :: MainTimeline / frame11()

并且

  

错误#2044:未处理的IOErrorEvent:。 text =错误#2036:加载从未完成。

正常加载游戏时效果非常好。当我在线上传并检查它是否正常工作时,此问题仍然存在。它没有。我的装载机适用于其他swf文件。怎么解决这个?

第1层代码,第11帧

  import flash.media.SoundChannel;
  var bgmusic2: loverswalk = new loverswalk;
  var bgmusic: spring = new spring;
  var forestmusic: NatureAmbiance = new NatureAmbiance;
  var cafemusic: cafeteria1 = new cafeteria1;


  var shopmusic: pamfluiteloop = new pamfluiteloop;

  var cash: CashRegisterChaChing = new CashRegisterChaChing;
  var beeps: beep = new beep;
  var musicboxsound: BlaclRockShooterMusicBox = new BlaclRockShooterMusicBox;
  var failsound: fail = new fail;
  var stgup: stageup = new stageup;
  var talkbg: talkbag = new talkbag;
  var ca: correct = new correct;
  var myChannel: SoundChannel = new SoundChannel();
  var bg: SoundChannel = new SoundChannel();
  var mb: SoundChannel = new SoundChannel();
  var myChanneltalk: SoundChannel = new SoundChannel();
  var lastpositionbg: Number = 0;
  var moodshop = 0;
  var dilbgrun = 0;
  var alertsound: alert = new alert;

第2层,第20帧



 var hp: int = 100;
 var day: int = 1;
 var week: int = 1;
 var money: Number = 0;
 var pendants: int = 0;
 var bracelets: int = 0;
 var comics: int = 0;
 var poetrys: int = 0;
 var tshirts: int = 0;
 var named: String = "Driver";
 var age: int = 17;
 var reply: int = 0;

 var dilrun: String = " ";
 var ncpvar: int = -1;
 var ncpvare: int = -1;
 var ncpvarm: int = -1;
 var flavie_stage: int = 0;
 var shannon_stage: int = 0;
 var vivette_stage: int = 0;
 var audrey_stage: int = 0;
 var gabriel_stage: int = 0;
 var toret: int = 0;

 function refresh1(event: Event): void {
   Object(this).bar.hp_text.text = String(hp);
   Object(this).bar.day_text.text = String(day);
   Object(this).bar.week_text.text = String(week);
   Object(this).bar.money_text.text = String(money);
 }



 function bedbtn(event: MouseEvent): void {
   alert_mc.gotoAndStop("Alert");
   alert_mc.alert_mc.alert_text.text = "You slept a night and gained a massive 100 HP. Enjoy!";

   hp = 100;
   day = day + 1;
   if (day == 8) {
     day = 1;
     week = week + 1;
   }

 }

 function woman(event: MouseEvent): void {


   if (event.target == audrey_btn) {
     if (hp >= 30) {
       hp = hp - 30;
       dilrun = "Audrey";
       dial_mc.gotoAndPlay("Dialogue");
     } else {
       alertsound.play();
       alert_mc.gotoAndStop("Alert");
       alert_mc.alert_mc.alert_text.text = "Go get some more HP silly!";
     }

   }
   if (event.target == shannon_btn) {


     if (hp >= 30) {
       hp = hp - 30;
       dilrun = "Shannon";
       dial_mc.gotoAndPlay("Dialogue");
     } else {
       alertsound.play();
       alert_mc.gotoAndStop("Alert");
       alert_mc.alert_mc.alert_text.text = "Go get some more HP silly!";
     }



   }
   if (event.target == vivette_btn) {
     if (hp >= 30) {
       hp = hp - 30;
       dilrun = "Vivette";
       dial_mc.gotoAndPlay("Dialogue");
     } else {
       alertsound.play();
       alert_mc.gotoAndStop("Alert");
       alert_mc.alert_mc.alert_text.text = "Go get some more HP silly!";
     }


   }
   if (event.target == gabriel_btn) {
     if (hp >= 30) {
       hp = hp - 30;
       dilrun = "Gabriel";
       dial_mc.gotoAndPlay("Dialogue");
     } else {
       alertsound.play();
       alert_mc.gotoAndStop("Alert");
       alert_mc.alert_mc.alert_text.text = "Go get some more HP silly!";
     }
   }
   if (event.target == flavie_btn) {
     if (hp >= 30) {
       hp = hp - 30;
       dilrun = "Flavie";
       dial_mc.gotoAndPlay("Dialogue");
     } else {
       alertsound.play();
       alert_mc.gotoAndStop("Alert");
       alert_mc.alert_mc.alert_text.text = "Go get some more HP silly!";
     }

   }
 }

 function NCP(event: MouseEvent): void {
   if (event.target == odile_btn) {

     if (hp >= 10) {
       hp = hp - 10;

       dilrun = "Odile";
       dial_mc.gotoAndPlay("Dialogue");
     } else {
       alertsound.play();
       alert_mc.gotoAndStop("Alert");
       alert_mc.alert_mc.alert_text.text = "You need more HP to talk to Odile.";
     }



   }
   if (event.target == elias_btn) {

     if (hp >= 10) {
       hp = hp - 10;

       dilrun = "Elias";
       dial_mc.gotoAndPlay("Dialogue");
     } else {
       alertsound.play();
       alert_mc.gotoAndStop("Alert");
       alert_mc.alert_mc.alert_text.text = "You need more HP to talk to Elias.";
     }



   }
   if (event.target == mikel_btn) {

     if (hp >= 10) {
       hp = hp - 10;

       dilrun = "Mikel";
       dial_mc.gotoAndPlay("Dialogue");
     } else {
       alertsound.play();
       alert_mc.gotoAndStop("Alert");
       alert_mc.alert_mc.alert_text.text = "You need more HP to talk to Mikel.";
     }



   }
 }

 function buy(event: MouseEvent): void {
   if (event.target == gifts_btn) {
     Object(this).menu_mc.gotoAndStop("Shop");
   }
   if (event.target == buy_food_btn) {
     Object(this).menu_mc.gotoAndStop("Cafe");
   }
 }


 function job(event: MouseEvent): void {
   alertsound.play();
   alert_mc.gotoAndStop("Alert");

   if (event.target == job1_btn) {
     if (hp >= 40) {
       hp = hp - 40;
       money = money + 30;
       alert_mc.alert_mc.alert_text.text = "You earnt 30 for 40 HP";
     } else if (hp < 40) {
       alert_mc.alert_mc.alert_text.text = "You don't have 40 HP to that. Better sleep or eat to gain more HP.";
     }
   }
   if (event.target == job2_btn) {
     if (hp >= 30) {
       hp = hp - 30;
       money = money + 20;
       alert_mc.alert_mc.alert_text.text = "You earnt 20 for 30 HP";
     } else if (hp < 30) {
       alert_mc.alert_mc.alert_text.text = "You don't have 30 HP to that. Better sleep or eat to gain more HP.";
     }
   }
   if (event.target == job3_btn) {
     if (hp >= 20) {
       hp = hp - 20;
       money = money + 10;
       alert_mc.alert_mc.alert_text.text = "You earnt 10 for 20 HP";
     } else if (hp < 20) {
       alert_mc.alert_mc.alert_text.text = "You don't have 20 HP to that. Better sleep or eat to gain more HP.";
     }
   }
 }
&#13;
&#13;
&#13;

如果我添加它们,其他帧将无法访问这些变量。

之前的加载程序代码:

&#13;
&#13;
var myrequest: URLRequest = new URLRequest("GAME.swf");
var myloader: Loader = new Loader();
myloader.load(myrequest);

myloader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progresshandler);
function progresshandler(myevent: ProgressEvent): void {

  var myprogress: Number = myevent.target.bytesLoaded / myevent.target.bytesTotal;


  bar_mc.scaleX = myprogress;
  percentage_text.text = Math.round(myprogress * 100) + "%";
}

myloader.contentLoaderInfo.addEventListener(Event.COMPLETE, finished);
function finished(myevent: Event): void {

  addChild(myloader);
  removeChild(percentage_text);
  removeChild(bar_mc);
  removeChild(background_mc);
}
&#13;
&#13;
&#13;

Loader Code After:

&#13;
&#13;
var myrequest: URLRequest = new URLRequest("GAME.swf");

import flash.net.URLRequest;
import flash.display.MovieClip;
import flash.events.Event;
var myloader: Loader = new Loader();


myloader.load(myrequest);

function progresshandler(myevent: ProgressEvent): void {

  var myprogress: Number = myevent.target.bytesLoaded / myevent.target.bytesTotal;

  bar_mc.scaleX = myprogress;
  percentage_text.text = Math.round(myprogress * 100) + "%";
}



myloader.contentLoaderInfo.addEventListener(Event.INIT, finished);

myloader.contentLoaderInfo.addEventListener(Event.COMPLETE, completes);


function finished(myevent: Event): void {

  addChild(myloader);
  removeChild(percentage_text);
  removeChild(bar_mc);
  removeChild(background_mc);
}

function completes(myevent: Event): void {


  var loaderInfo: LoaderInfo = myevent.target as LoaderInfo;
  var swf: Object = loaderInfo.content;
  swf.play();

}
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

也许你应该尝试一下这个事件:ADDED_TO_STAGE。 将对象添加到stage(非常好奇的名称和关联)时,即执行addChild方法时,会触发ADDED_TO_STAGE事件。

尝试在外部SWF的Main类中侦听此事件,因此,在将此相应对象添加到舞台之前,不会执行任何代码(现在即使在加载过程中也可以听到音乐。

按照一些例子:

 package 
 {
        import flash.display.Sprite;
        import flash.events.Event;

        public class TheMainClassOfYourExternalSWF extends Sprite 
        {
               public function TheMainClassOfYourExternalSWF() 
               {
                    addEventListener(Event.ADDED_TO_STAGE, initHandler);
               }

               private function initHandler(event:Event):void 
               {
                    removeEventListener(Event.ADDED_TO_STAGE, initHandler);
                    trace('this is the stage:', stage);
                    trace('this is my parent:', this.parent);
                    // here you start to include your logic
               }
        }
  }

如果您使用的是FLA文件并使用时间轴添加代码,则可以尝试:

 addEventListener(Event.ADDED_TO_STAGE, initHandler);

 function initHandler(event:Event):void 
 {
         removeEventListener(Event.ADDED_TO_STAGE, initHandler);
         // here you start to include your logic, call your functions, initialise your instances...
 }

答案 1 :(得分:0)

加载外部swf时,有两件事需要注意。

首先,当Event.INIT触发Event.ITPLETE时,加载的swf的第一帧开始播放。当整个swf加载完成时触发第一帧时触发事件初始化。

第二阶段或root只有在加载到添加到舞台的显示列表中时才能在加载的swf中使用。当Event.INIT触发时,加载的swf没有stage或root,因此swf的第一帧不应该有对stage或root的任何引用。

如果您不使用swf的文档类,那么只需使用stop()将第一帧设置为空,然后加载并添加到显示列表后,将swf转到第2帧,其中包含所有代码。< / p>