4 Replies Latest reply on Sep 9, 2007 10:42 PM by Greg Dove

    loaded swf aspect ratios - what's the best approach

    Greg Dove Level 4
      I've just finished a piece of work for maintaining the aspect ratio of a loaded swf in a 'player' for banner advertising. Basically the player stage can be any size and whatever is loaded is centered vertically and horizontallly, and theres a 'play' and stop button and sound controls etc which lay themselves out sensibly.

      Got it all working no problems.... but I would like to check one thing if anyone can advise.
      When you check a loaded swf's _width and _height properties in an onLoadInit handler... that obviously reports the actual width and height of the visual assets in the loaded swf's frame 1 (let's say for sure that's where its playhead is). Is there any way to get hold of the original stage width and height properties that swf had when it was created? These can be quite different things and its the latter pair that I'm after.

      My approach has been to make a requirement that the loaded 'banner' swfs have a rectangular background clip at 0,0 on the first frame (and nothing else that would overlap it) that represents their size and aspect ratio, and just getting these dimensions in an onLoadInit handler.

      I'm just wondering am I missing something obvious - i.e. is there a simpler approach - am I over-complicating things - or is the way I'm doing it the simplest way? I guess what would be ideal is if there was a property accessible that represented the stage width and height properties that the 'banner' swf had when it was created - but I don't know (yet) of anything like this. But I have been known to miss really obvious things before... so please tell me if I am.

      If you can understand the above explanation then my question is simple:can I avoid the 'sizing' background requirement in the loaded banner ads or not? TIA - GWD
        • 1. Re: loaded swf aspect ratios - what's the best approach
          kglad Adobe Community Professional & MVP
          not with as2. you can find the maximum dimensions used by graphic assets throughout the loaded swf's timeline (not just those on frame 1), but if there's nothing on-stage in any main timeline frame, the loaded swf's width and height will be reported as zero.
          • 2. Re: loaded swf aspect ratios - what's the best approach
            Greg Dove Level 4
            thanks kglad. I had pored over everything I could find and couldn't think of another way to do it, so its reassuring (although disappointing) to hear that there is none.
            I just used frame1 because the 'player' prevents the loaded clip from playing unless someone clicked..so its in a 'pause' state on frame one.

            Out of curiosity what is the method to check the dimensions of an arbitrary frame... can you do that without moving the clips playhead or do you just move the playhead and then check _width and _height, then move it back again for example?

            and when you say 'not with as2' I presume that means you can with as3? I really need to start working in as3. thanks again.

            • 3. Re: loaded swf aspect ratios - what's the best approach
              kglad Adobe Community Professional & MVP
              to check the dimensions of the frame with the largest bounding rectangle you can use the code below. and yes, you must move the playhead to find it.

              and yes, in as3 you can determine the stage dimensions using stageHeight and stageWidth properties of the stage class.

              • 4. loaded swf aspect ratios - what's the best approach
                Greg Dove Level 4
                Thanks again. Its good to know that approach for measuring a clip if I ever need it.

                I guess I'll have to check out the as3 option. I just had a quick look at the docs.
                The livedocs suggest otherwise (that all stage properties - even for loaded swfs- refer to the main Stage object or to null if they are not in the display list). What I was hoping for was some property related to the original dimensions of the stage when the swf was published. But I know for a fact that all the as2 documentation is not always correct and I haven't tried it in as3 yet, so I will.

                I found an encouraging comment at the bottom of the livedocs page for "Stage" in as3. If the docs are correct for Stage, then LoaderInfo width and height properties look promising for what I want to do.