Jump to content
Search Community

Content.width issue

tkk11 test
Moderator Tag

Recommended Posts

Hi. I'm having some issues trying to figure out the native width and height of a SWF I'm loading. Here's my code:

var headerLDR:SWFLoader = new SWFLoader(path+"Header.swf",{name:"header",  onComplete:headerComplete});
headerLDR.load();


function headerOncomplete(e:LoaderEvent)
{
trace(e.target.content.width); //gives me "0", which is certainly incorrect
trace(e.target.rawContent.width); //also gives me 0
var rawContent:DisplayObject = e.target.rawContent; //works, I can addChild and it shows up just fine.
var bounds:Rectangle = rawContent.getBounds(rawContent);
trace("native width: " + bounds.width + ", height: " + bounds.height); //outputs "native width: 0, height: 0"
}

 

Any idea why it can't get the width and height of the SWF? Every thing I've tried from the documentation and other posts on this forum gives me an output of 0. Thanks in advance.

Link to comment
Share on other sites

e.target.content.width

and e.target.rawContent.width

 

should work fine. although it seems the width is not the size of the stage. it is the width of the contents of the stage.

do you have anything on the stage of your header.swf in frame 1?

Link to comment
Share on other sites

You could also use the loaderInfo to get the actual swf's native size regardless of its content. It sounds like the problem with your swf is that on the first frame, there's nothing there yet - maybe it's subloading your video or something. So if you just get the "width" of the DisplayObject, that is always dictated by the contents of the DisplayObject, so if it is empty, the width will be zero. If you just want to get the native size, though do something like:

 

e.target.rawContent.loaderInfo.width;

Link to comment
Share on other sites

Odd, it's saying I've got a null object reference when I try to do trace(e.target.rawContent.loaderInfo.width); or any other property of loaderInfo.


var headLDR:SWFLoader = new SWFLoader(path+cFolder+"Header.swf",{name:"header", alpha:1, onComplete:headComplete});
headLDR.load();

function headComplete(e:LoaderEvent)
{
  trace(e.target.rawContent.loaderInfo.width);
}

 

gives me the following output:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com::chapterPage/headComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.greensock.loading.core::LoaderCore/_completeHandler()
at com.greensock.loading::SWFLoader/_completeHandler()

 

When I run "trace(e.target.rawContent.loaderInfo.url)" it gives me the same error, and tracing "e.target.rawContent.loaderInfo" gives me "null". Odd, because there's definitely something in there. Calling the loader directly, or putting it in a queue with the name "header" and calling with 'queue.getLoader("header")' does the same thing. This method works fine for my image loaders.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...