FLV: How to stop a VideoPlayer from scaling along with its containing MovieClip?

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!

Answers


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;
}

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.


Need Your Help

ios app hits straight shouldstartloadwithrequest after coming from background instead

ios ios5.1 uiapplication openurl

I have a webview in my mainviewcontroller and i am laoding a webpage in viewdidload method as below:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.