0
votes

I am loading an external movie clip in my SWF. The stage scale mode is "no scale" and stage align is TOP LEFT. I am resizing move clip to the actual height and width of parent movie clip using following in OnResize event:

object.x = stage.x;
object.y = stage.y;
object.width = stage.stageWidth;
object.height = stage.stageHeight;

But it's not working. Two important points:

  1. It was working earlier when was using Flash Player older than 10.
  2. Now, it works only when I resize the window. I just can't understand why it's creating the problem.

Any help of any sort would be highly appreciated as I am blocked just coz of this. I don't want to use exact fit scale mode of the stage.

Thanks!

2
when you say "its not working" what is it actually doing? the parent swf is set to no_scale = so its filling up whatever container its in. How do you have the stageScaleMode of the child set up? If it, too, is set to no_scale, then it "should" also fill the available space (though I've found that particular scenario to be pretty finicky). If its set to SHOW_ALL (the default) then it must be manually scaled up by the parent.Bosworth99

2 Answers

1
votes

Remember that the object.height and object.width refers to the active content on the object depending on how you're importing it:

    import flash.net.URLRequest;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.display.MovieClip;

    function startLoad()
    {
    var mLoader:Loader = new Loader();
    var mRequest:URLRequest = new URLRequest("test.swf");
    mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
    mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
    mLoader.load(mRequest);
    }

    function onCompleteHandler(loadEvent:Event)
    {
            var object:MovieClip = loadEvent.currentTarget.content;
            object.x = stage.x;
            object.y = stage.y;
            trace(object.width);
            trace(stage.stageWidth);
            object.width = stage.stageWidth;
            trace(object.height);
            trace(stage.stageHeight);
            //object.height = stage.stageHeight;

            addChild(object);


}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();

That code above works, but you may be stretching the width to the point where the content is being stretched out of the scene, trace the width and height.

EDIT:

for youtube it would be something like this:

var loader:Loader = new Loader(); - global variable

function initialzer(){
       loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
       loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
}

private function onLoadInit(event:Event){
    addChild(loader);
    loader.content.addEventListener("onReady", onPlayerReady);
    loader.content.addEventListener("onError", onPlayerError);

}

function onPlayerReady(event:Event):void {
    player = loader.content;
    player.width = 111;
    player.height = 111;
}
0
votes

You're probably applying the transformation before the object has been added to the stage and thus, the stage reference is null and or its properties are null. You should add the event listener to the object Event.ADDED_TO_STAGE and then within the callback of the event, apply your transformations. Also you don't need to access the stage object through object.stage, the stage should be a static entity that you can call from either within the object or outside of it. If you cannot access the stage by simply typing "stage" from within the scope where you are applying this transformation then this would probably be the cause of the issue. Like I said, try using the ADDED_TO_STAGE event, apply the transformations within that callback and everything should be okay if I'm right. Also when you're trying to cast an object like you've posted above, use the "as" keyword. Example:

var object:MovieClip = loadEvent.currentTarget.content as MovieClip;

Your statement that the youtube player "doesn't support this method" doesn't really make sense, since this had nothing to do with youtube or any other external API. Casting/type conversion is a programming language feature. The only case where this statement would be true is if the youtube player had no common inhertence with the MovieClip object, in which case you'd get a type coercion error at runtime (maybe even compile time in some instances) telling you that you simply cannot cast an object as a completely different object. Anyway hope this helps.