|
-
Total Universe Mod
height not right
Create two .fla's called SizeParent.fla and SizeChild.fla.
In SizeChild draw a box of anysize and set it's y to anywhere but 0.
Publish SizeChild.swf and place this code on frame 1 in SizeParent
Code:
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
l.load(new URLRequest("SizeChild.swf"));
function onComplete(e:Event):void{
addChild(l);
trace(l.content.height);
}
Shouldn't height be the value of your box's y plus its height? I keep getting just the height of the box.
What gives?
-
isnt this "normal" ?
i am working on external swf right now, its size is set to 1280 x 900, but it only has a mc 140px tall and stageWidth long inside which lies somewhere on the middle and if i trace from my main movie:
trace(swfLoader.content.height);
i get 140
-
Senior Member
In both of your cases you measure the main timeline of the movie, which is not the stage. The main timeline only measures the objects present and kind of creates a rectangle covering all objects. The width and height is different from the stage unless you create a box of the stage dimensions.
To get the stage size of a movie you need to trace stage.stageWidth (or stageHeight). A child movie will lose the stage and get the stage properties of its parent once loaded. So this
trace(e.currentTarget.content.stage.stageHeight);
would trace the height of the parent movie stage.
- The right of the People to create Flash movies shall not be infringed. -
-
Total Universe Mod
It may be normal but it's not what I want.
I'm not trying to read the stageHeight. I'm trying to read the bounds of a loaded swf. The stageHeight is meaningless in this case because the contents of the loaded swf may come out to any height based on the length of an xml object.
In as2, if you created a new movie clip and placed it at 0,0. Then attached a 20x20 movie clip inside of it at a y of 10, reading the height of that clip would give you 30. In as3, since Loader is a displayobjectcontainer, adding your loader instance directly to the root stage should yield the same behavior.
-
Senior Member
The timeline itself is a Displayobjectcontainer. However, width and height are Displayobject properties. When you have a shape or textfield then you have a pure Displayobject and the width will give the exact size of the objects. Think about the width and size of Movieclips is also determined by its content. If you place the shape into an empty Movieclip the Movieclip size will now have the size of the shape no matter where it is located with regard to the centerpoint, since the MovieClip is a Displayobjectcontainer.
If you want the size of your child movie place some variables in a frame. Then you can call the variables when the movie is loaded. In your childmovie:
var mh:int=400;
var mw:int=550;
in your parent movie after loading:
trace (MovieClip(l.content).mh);
getBounds and getRect will give you coordinates:
trace (getBounds(MovieClip(l.content)));//(x=100, y=79, w=207.95, h=279.55)
You don't need to use content just (l).height, since the loader now contains the child.
- The right of the People to create Flash movies shall not be infringed. -
-
Total Universe Mod
Thanks Cancer.
That fact that a displayobjectcontainer would reveal it height based solely on the total pixels of its children with complete disregard of its own x and y is f*cking stupid. That's an entirely new and virtually useless way to handle dimensions in as3.
I figured out the getBounds() fix earlier today and posted here about it but for some reason that post is not in this thread. Anyway thanks for the help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|