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:
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.
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!