EDIT: I have since solved this problem by simply reworking my MXML-based app and using the SWFLoader component to get the desired effect, without any reloading necessary. This question is therefore no longer an issue for me, but I leave it open for reference.
In MXML, I can get the desired effect easily:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:SWFLoader width="100%" height="100%"
source="3298.swf"/>
</mx:Application>
It looks like this:
(external SWF fills stage) http://www.ubuntu-pics.de/bild/40036/screenshot_028_MSd0UZ.png
I'm new at ActionScript, though, so I can't quite figure out how to duplicate this without MXML. Here's the relevant class:
package {
import flash.net.URLRequest;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.events.Event;
public class Asset extends Loader {
public var id:int;
private var preview:Preview;
private var swfContent:DisplayObject;
public var zone:int;
public function Asset(data:Object) {
id = data.id;
zone = data.zone;
}
public function loadInto(previewToSet:Preview):void {
preview = previewToSet;
var request:URLRequest = new URLRequest(url);
contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
load(request);
}
private function onCompleteHandler(loadEvent:Event):void {
swfContent = loadEvent.currentTarget.content;
swfContent.scaleX = 1;
swfContent.scaleY = 1;
preview.addChild(swfContent);
}
private function get url():String {
开发者_运维知识库 return id + ".swf";
}
}
}
In the loadInto
function I give the Asset
a sprite to live on, and it starts to load. I can get pretty close by setting scaleX
and scaleY
each to 1, but I can't quite figure out why it's not at the top, and why the SWF is just a bit to large.
(external swf slightly off) http://www.ubuntu-pics.de/bild/40040/screenshot_029_4pHKNI.png
How can I duplicate MXML's 100% height and width in pure ActionScript? Is it doable? If not, I have a fallback app in pure MXML, but my implementation there involves loading the SWFs every time I want to add or remove any one of them... it's not perfect. So I'd prefer this type of implementation if I can just figure out the sizing issue.
Thanks!
Use the resize event from the stage object and each time the resize event is fired resize the content according to that:
stage.addEventListener(Event.RESIZE, onResize);
public function onResize(e:Event):void{
swfContent.width=stage.stageWidth;
swfContent.height=stage.stageHeight;
}
try adding
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
to the start of your class then size and place the loaded image to
loadedimage.x = loadedimage.y = 0;
loadedimage.width = stage.stageWidth;
loadedimage.height = stage.stageHeight;
This sound like the anchor point of your swf is not precisely in it's corner. Try offsetting the x and y position in your code, or, even better, modifying the swf to have the anchor point in the corner ?
精彩评论