0

SWF をロードおよびアンロードするクラスを生成しましたが、視覚的には swf にロードされていないように見えますが、エラーも返されません。

親コード:

 //specify the path for the child SWF
  var PageURL:URLRequest = new URLRequest("home/home_index.swf");

//include the SWF loading class 
import MM_swfloader;
var mainPage:MM_swfloader = new MM_swfloader();
//evoke the load
mainPage.LoadSWF(PageURL);

MM_swfloader クラス:

package  {

import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;  
import flash.net.URLRequest;
/**
 * author: Me
 * email: lala@lala.com
 **/

public class MM_swfloader extends Sprite {

    public var loader:Loader = new Loader();
    public function MM_swfloader():void
     {
        // constructor code
     }

    public function LoadSWF(val:URLRequest):void{
        var loader:Loader = new Loader();
        loader.load(val);
        addChild(loader);
trace("loaded"); //returns true
    }

    public function UnLoadSWF():void {
        loader.unload();
    }

  }

} 

読み込まれた SWF がどこに読み込まれているのかわかりません。何か案は?

4

2 に答える 2

1

親のステージにinstanceSWF ロードのを追加する必要があります。classclass

//specify the path for the child SWF
var PageURL:URLRequest = new URLRequest("home/home_index.swf");

//include the SWF loading class 
import MM_swfloader;
var mainPage:MM_swfloader = new MM_swfloader();
// add the instance to the stage
this.addChild(mainPage);
//evoke the load
mainPage.LoadSWF(PageURL);

また、ローダーのコードにはいくつかの問題があり、class以下で修正しました (説明についてはコメントを参照してください)。

// Poor practice to use the default namespace, stick it in com.lala 
package  {

import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;  
import flash.net.URLRequest;
/**
 * author: Me
 * email: lala@lala.com
 **/

public class MM_swfloader extends Sprite {

    public var loader:Loader = new Loader();

    public function MM_swfloader():void
    {
        // constructor code

        // listen for loader complete on the loader instance
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);

        // add loader to stage
        this.addChild(loader);
    }

    // Note that by convention loadSWF would be a better name for this method
    public function LoadSWF(val:URLRequest):void {
        // commented out to avoid creating a new locally-scoped
        // loader each time the method is called
        //var loader:Loader = new Loader(); 

        loader.load(val);

        // commented out to avoid adding child each time
        // method is called, added in constructor instead
        //addChild(loader);

        // loading is asynchronous, this needs to be in a handler
        // for the loader.complete event
        //trace("loaded"); //returns true
    }

    // call this unloadSWF
    public function UnLoadSWF():void {
        loader.unload();
    }

    // handler for loader.complete event
    private function loaderCompleteHandler(event:Event):void {
        trace("loaded");
    }   
  }
} 
于 2012-08-11T00:04:12.267 に答える
0

次のように、ローダーのコンテンツを完全にステージに追加する必要があります。

import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;

function startLoad()
{
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("someswf.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}

function onCompleteHandler(loadEvent:Event)
{
        addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();
于 2012-08-10T19:43:31.647 に答える