記住object.height和object.width是指在物體上的活動內容取決於你如何將其導入:
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.MovieClip;
function startLoad()
{
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("test.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event)
{
var object:MovieClip = loadEvent.currentTarget.content;
object.x = stage.x;
object.y = stage.y;
trace(object.width);
trace(stage.stageWidth);
object.width = stage.stageWidth;
trace(object.height);
trace(stage.stageHeight);
//object.height = stage.stageHeight;
addChild(object);
}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();
上述作品該代碼,但你可能會拉幅到內容被伸出場景的地方,追蹤寬度和高度。
編輯:
YouTube的它會是這樣的:
var loader:Loader = new Loader(); - global variable
function initialzer(){
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
}
private function onLoadInit(event:Event){
addChild(loader);
loader.content.addEventListener("onReady", onPlayerReady);
loader.content.addEventListener("onError", onPlayerError);
}
function onPlayerReady(event:Event):void {
player = loader.content;
player.width = 111;
player.height = 111;
}
當你說「它不工作」它實際上在做什麼?父swf被設置爲no_scale =,因此它填充了其中的任何容器。您如何設置子級的stageScaleMode?如果它也被設置爲no_scale,那麼它「應該」也填充可用空間(雖然我發現特定的場景非常挑剔)。如果其設置爲SHOW_ALL(默認值),那麼它必須由**手動**由父級放大。 – Bosworth99 2011-03-23 00:58:20