views:

430

answers:

2

I'm creating a VideoPlayer object in a swf and that works well. I'm sizing it using autoSize and that's working fine too. I'm trying to make it so that when the containing swf gets larger the video stays at the same size. The swf is actually loaded from another flash movie which is where the resizing happens. Is there a setting in the VideoPlayer class or in the movieclip I can set to make it stop scaling along with the movieclip?

Thanks!

+1  A: 

Hey there Jon,

I do not believe the exact method you want will work. It seems to me that the MovieClip object, which is a DisplayObjectContainer, or extends DisplayObjectContainer, utilizes a Composite design pattern where in it's children are affected when it is affected. Think about making a movieclip as below:

var mc:MovieClip = new MovieClip();
addChild(mc);

var mcChild:MovieClip = new MovieClip();
mc.addChild(mcChild);

now if you move the parent, mc, mcChild moves the exact amount of pixels preserving its "x" and "y" positions as well as all other attributes.

That all being said, what you need is to place your VideoPlayer on the outside of the resizeable movieclip. It is quite likely that once the movieclip's size changes you may want to position the video player in the same relative position.

var mc:MovieClip = new MovieClip();
addChild(mc);

var vp:VideoPlayer = new VideoPlayer();
vp.x = mc.x + 10;
vp.y = mc.y + 10;
addChild(vp);

/**
 *If mc's registration point is "Top-Left" then adjustments aren't 
 *required because mc will span down and to the right, otherwise we
 *need to reposition the video.
 */
function resizeMovie(pWidth:Number, pHeight:Number):void
{
    mc.width = pWidth;
    mc.height = pHeight;

   adjustVideo();
}
function repositionMovie(pX:Number, pY:Number):void
{
    mc.width = pWidth;
    mc.height = pHeight;

   adjustVideo();
}
function adjustVideo():void
{
    //This is where we make sure of vp's positioning upon mc's change.
    vp.x = mc.x + 10;
    vp.y = mc.y + 10;
}

So anytime we affect the main, we can affect other objects in our own manner. This same idea works with resizing of the stage.

stage.addEventListener(Event.RESIZE, onStageResize);
function onStageResize():void
{
    //Make mc the size of the stage
    mc.width = stage.stageHeight;
    mc.height = stage.stageHeight;

    //Position video in relation to mc
    adjustVideo();
}

In the end, MovieClip is set to adjust its children relative to how itself is being adjusted. As a DisplayObjectContainer it makes sense that the items inside of it are dictated by the parent (the movieclip) and to accomplish what you want you merely need to abstract your video player out of the swf and make changes to it accordingly.

Brian Hodge

http://www.hodgedev.com

Brian Hodge
+1  A: 

Not that I've tested it, but maybe you could add a handler for Event.RESIZE in the swf which contains the video player. Then do something like this:

private function onResize(e:Event):void
{
  childClip.scaleX = (scaleX != 0) ? (1 / scaleX) : 0;
  childClip.scaleY = (scaleY != 0) ? (1 / scaleY) : 0;
}
Sean
I like the thought, and at first I went there myself, but I just dont like affecting scale personally; Then again I freak out if a display object's x and y aren't integers.
Brian Hodge
We all have our preferences, I suppose. I would pull my hair out over the hard-coded numbers, which many Flash developers don't seem to care about.
Sean
I ended up using a variation of this to make this feature work for me. Thank you.
Jon
No prob, what was your variation? I'm curious what the final solution would be, having never actually tried this.
Sean
Well my smaller clip was growing at a different rate in proportion to the rest of the movie so I needed to calculate the difference and then apply it to the scale of the flv. I had to think about it over a weekend but it ended up working very well.
Jon