0

フレームアクションで書いたときに動くプリローダーのコードを作りました。しかし、その後、すべてのコードをクラスに移動し、少し作り直すことにしました。そして今、それは機能しません。リスナーが呼び出す必要がある関数が呼び出されていないだけで、この呼び出されていない関数で引数イベントにアドレス指定するとエラーが発生し始めました。

package  {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.ProgressEvent;

    public class Preloader extends MovieClip {
        public function Preloader() {
            addEventListener(Event.ADDED_TO_STAGE, init);
        }
        private function init(e:Event):void {
            trace("init started");
            removeEventListener(Event.ADDED_TO_STAGE, init);
            loaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);  
            trace("init completed");
        }
        private function showProgress(e:Event):void {
            trace(loaderInfo.bytesLoaded);
            /*info_txt.text = Math.floor(e.bytesLoaded/e.bytesTotal*100) + "%"
            if (e.bytesLoaded==e.bytesTotal) {
            loaderInfo.removeEventListener(ProgressEvent.PROGRESS, showProgress);   
            finalizeLoading();
            }
            /**/
        }
        private function finalizeLoading():void {
            removeChild(info_txt);
            var startGame_btn = new StartGame_btn();
            addChild(startGame_btn);startGame_btn.x=395;startGame_btn.y=290;
        }
    }       
}

/*info_txt... 部分のコメントを外すと。私はこれを得る:

Access of possibly undefined property bytesLoaded through a reference with static type flash.events:Event.
Access of possibly undefined property bytesTotal through a reference with static type flash.events:Event.
Access of possibly undefined property bytesLoaded through a reference with static type flash.events:Event.
Access of possibly undefined property bytesTotal through a reference with static type flash.events:Event.
4

2 に答える 2

0

あなたのコードには多くの間違いがあります。

これは、いくつかのコードが追加された単純なローダーです。最悪の場合、それはあなたを正しい方向に向けるはずです。

package  {
    import flash.display.MovieClip;
    import flash.errors.IOError;
    import flash.events.AsyncErrorEvent;
    import flash.events.ErrorEvent;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.ProgressEvent;
    import flash.events.SecurityErrorEvent;

    public class myPreloader extends MovieClip {
        public var context:LoaderContext = new LoaderContext();
        public var myLoader:Loader = new Loader();

        public var url:URLRequest;
        public function myPreloader() {
            context = new LoaderContext();
            context.checkPolicyFile = true; 
            myLoader = new Loader();

            myLoader.addEventListener(AsyncErrorEvent.ASYNC_ERROR, errorHandlerAsyncErrorEvent);
            myLoader.addEventListener(IOErrorEvent.IO_ERROR, errorHandlerIOErrorEvent);
            myLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandlerSecurityErrorEvent);
            myLoader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
            myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, infoIOErrorEvent);
            myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);
            myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);

            this.addEventListener(Event.ADDED_TO_STAGE, init);
        }
        private function init(e:Event):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            url = new URLRequest("test.swf"); // change this to whatever it is you are loading
            myLoader.load( url,context );
            myLoader.load( url);
        }
        public function progressListener (e:ProgressEvent):void{
            trace("Downloaded " + e.bytesLoaded + " out of " + e.bytesTotal + " bytes");
            info_txt.text = info_txt.text = Math.floor(e.bytesLoaded/e.bytesTotal*100) + "%"
        }
        public function onLoadComplete( e:Event ):void{
            trace( 'onLoadComplete' );
            removeChild(info_txt);
            var startGame_btn = new StartGame_btn();
            addChild(startGame_btn);
            startGame_btn.x = 395;
            startGame_btn.y=290;
        }
        public function initHandler( e:Event ):void{
            trace( 'load init' );
        }
        public function errorHandlerErrorEvent( e:ErrorEvent ):void{
            trace( 'errorHandlerErrorEvent ' + e.toString() );
        }
        public function infoIOErrorEvent( e:IOErrorEvent ):void{
            trace( 'infoIOErrorEvent ' + e.toString() );
        }
        public function errorHandlerIOErrorEvent( e:IOErrorEvent ):void{
            trace( 'errorHandlerIOErrorEvent ' + e.toString() );
        }
        public function errorHandlerAsyncErrorEvent( e:AsyncErrorEvent ) :void{
            trace( 'errorHandlerAsyncErrorEvent ' + e.toString() );
        }
        public function errorHandlerSecurityErrorEvent( e:SecurityErrorEvent ):void{
            trace( 'errorHandlerSecurityErrorEvent ' + e.toString() );
        }
    }
}
于 2013-09-11T14:17:15.360 に答える
0
  1. ルート loaderInfo オブジェクトをリッスンするメソッド内に変更loaderInfoします。スクリプトがタイムラインオブジェクトにあるときは、documentClass とルートが同時にあったため、コードは適切に機能しました。root.loaderInfoinitthis

  2. エラーについては、そのようなプロパティが与えられていないため、メソッドでe引数のタイプを からEventに変更するだけです。ProgressEventshowProgressEvent

于 2013-09-11T13:50:45.317 に答える