2010-11-23 10 views

答えて

1

実際、これは非常に一般的な方法です。

外部プリローダーファイルはLoaderクラスのインスタンスをインスタンス化してから、ペイロード.swfをロードするだけです。ペイロードがロードされている間、ProgressEvent.PROGRESSをリッスンして、ロードバーなどの何らかの更新を行うことができます。これは次のようになります。

package 
{ 
    import flash.display.Loader; 
    import flash.display.MovieClip; 
    import flash.events.Event; 
    import flash.events.IOErrorEvent; 
    import flash.events.ProgressEvent; 
    import flash.net.URLRequest; 

    public class Preloader extends MovieClip 
    { 
     // this loads in your main swf 
     public var loader:Loader; 

     // this points to the location of your main swf 
     public var request:URLRequest; 

     // this holds a reference to your main swf once it's been loaded in. 
     public var content:MovieClip; 

     public function Preloader() 
     { 
      addEventListener(Event.ADDED_TO_STAGE, addedHandler); 

      super(); 
     } 

     // it's a good practice to wait for ADDED_TO_STAGE before you start doing stuff, that way you can avoid certain Null Reference Errors 
     protected function addedHandler(e:Event):void { 
      removeEventListener(Event.ADDED_TO_STAGE, addedHandler); 

      loader = new Loader(); 
      request = new URLRequest("path/to/your/file.swf"); 

      loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler); 
      loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler); 
      loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler); 
     } 

     // This will fire when your main swf is loaded in. 
     protected function completeHandler(e:Event):void { 
      loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHandler); 
      loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, errorHandler); 
      loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressHandler); 

      trace("Load completed! Now we're going to add the target swf to the timeline:"); 

      content = MovieClip(loader.content); 

      /* 
      *  Additional logic can go here to remove your loadbar or etc. 
      */ 

     } 

     // this will fire if there's a problem with loading in the swf 
     protected function errorHandler(e:IOErrorEvent):void { 
      trace("Error: the path specified was incorrect. Unable to find that file. Here's the error in full:\n " + e) 
     } 


     // this will fire constantly while the target swf is being loaded, so you can see how much more you have to load. 
     protected function progressHandler(e:ProgressEvent):void { 
      var perLoaded:Number = 100* (e.bytesLoaded/e.bytesTotal) 
      trace("Percent Loaded: " + perLoaded); 

      /* 
      * Additional logic can go here to update your load bar, etc. 
      */ 

     } 
    } 
} 
+0

これは私が必要とする正しいアプローチであるかどうかはわかりません。フラッシュプロジェクト私はすでに他のものがロードされるまで回転し、プリローダーが存在しないか存在する次のフレームに行くローダーを持っています。だから、私はちょうど外部のaminmationをロードし、アニメーションを停止するか、他のものがロードされたら消えるようにしたい。 – mcgrailm

+0

ああ、そうだ。それはもう少し複雑です - あなたは、その場であなたのローダークラスを生成するために何らかの種類のファクトリパターンを使うことができますが、それでもフレーム1 /フレーム2のエクスポートトリックをしているなら、それがうまくいくかどうかはわかりません。短い答え:それは可能ですが、あなたのプロジェクトの設定方法に応じていくつかのことをするかもしれません。 – Myk

関連する問題