tags:

views:

1604

answers:

4

I have a class which extends SWFLoader, I use it like a normal SWFLoader:

var loader:MySWFLoader = new MySWFLoader();
loader.load("myFile.SWF");
myScene.addChild(loader);

The loading works OK, except that it remains 0 because the width & height never change from 0. I had to override the width/height get properties to make it work:

class MySWFLoader extends SWFLoader
{
public override function get width():Number{    return contentWidth; }
public override function get height():Number{   return contentHeight; }
}

As well as being a big hack this isn't quite correct; especially since the SWF has multiple frames and the frames are of different width/height.

Why aren't width/height working in the first place? Shouldn't they be automatically set during loading? Is it possible the issue lies with the SWF itself somehow?

Update: Changing scaleContent to true or false makes no difference.

A: 

By default the SWFLoader scales the content to the size of the loader, so you have to set the size of the loader. If you want the loader to scale to the size of the content then you have to set the scaleContent property to false.

Gerald
A: 

I'm not sure what part of the cycle you're trying to grab the height and width (and is it of the loader object or the loaded content) but you can can access the height and width of the loaded object using SWFLoader.loaderInfo.height and SWFLoader.loaderInfo.width.

onekidney
A: 

SWFLoader is a UIComponent.

It needs to be run through the UIComponent framework to set its dimensions correctly

In other words, it is waiting for calls to commitProperties(), updateDisplayList(), etc.

If you drop it in your application (so that it is part of the layout framework) it should be fine.

Brian
+2  A: 

I'm not sure if this applies for SWF loading, but whenever I'm loading content, i cannot access width and height before the whole thing is loaded.

So make an event listener that listens when the loading is completed, and then read the height/width.

Also take a look at the loaderInfo class in AS3

Kasper