We help IT Professionals succeed at work.

how to change size of embedded movie clip.

I have finally figured out how to embed an external swf (a rotating slideshow/banner) in my flash file, however, for some reason the embedded swf is blown to an extremely large proportion. How do I set the loaded swf movie clip size? The slideshow is in a movieclip that some actionscript on the main timeline opens the external swf in. Here is that script...

var imageLoader:Loader;
var ldr:Loader = new Loader();
ldr.load (new URLRequest("slideshow.swf"));
ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ldError);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, ldComplete);
slideshow.addChild(ldr);
stop()
function ldComplete(ev:Event)
{
}
function ldError(ev:Event)
{
}

That is on the slideshow movieclip first frame on main timeline. When I was using an as2 based slideshow the embedded swf was the right size...now that I have switched to as3 to get everything functioning correctly the slideshow is blown way out of proportion. How would I set the proportion of slideshow.swf back to what they should be(569x163)? Could I simply modify the above code? How would I? That seems like the place to do it because when I play the slideshow alone it is the correct size.

Thanks ahead of time for the help!
Comment
Watch Question

have you tried setting ldr.width and ldr.height.

it should help

Author

Commented:
I would but I don't know how... Thanks!

Author

Commented:
ok I tried adding it like this but it didn't work. the swf did not appear
...
var imageLoader:Loader;
var ldr:Loader = new Loader();
      ldr.width = 569;
      ldr.height = 163;
ldr.load (new URLRequest("slideshow.swf"));
ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ldError);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, ldComplete);
slideshow.addChild(ldr);
stop()
function ldComplete(ev:Event)
{
}
function ldError(ev:Event)
{
}
I had a similar problems when loading external swf's into a main movie that has a fluid (re-sizable) layout. I solved it by placing the following code in the first frame of all the swf's that I loaded:

stop();
//Important! Initiate when completely loaded

function isLoaded():void {
      addEventListener(Event.ADDED_TO_STAGE, init);
}
isLoaded();
function init(e:Event):void {
      removeEventListener(Event.ADDED_TO_STAGE, init);
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;
      stage.addEventListener(Event.RESIZE, sizeListener);
      stage.dispatchEvent(new Event(Event.RESIZE));
}

And in case you were wondering, I use the following code to load swf's with a preloader:

//preloader
var _swfLoader:Loader;
var _swfContent:MovieClip;
function loadSWF(path : String):void {
      var _req : URLRequest = new URLRequest ();
      _req.url = path;
      _swfLoader = new Loader ();
      setupListeners(_swfLoader.contentLoaderInfo);
      _swfLoader.load(_req);
}
function setupListeners(dispatcher : IEventDispatcher):void {
      dispatcher.addEventListener(Event.COMPLETE, addSWF);
      dispatcher.addEventListener(ProgressEvent.PROGRESS, preloadSWF);
}
function preloadSWF(event : ProgressEvent):void {
      var _perc : int = (event.bytesLoaded / event.bytesTotal) * 100;
      percentTxt.text = _perc + "%";
      progress_mc.gotoAndStop(_perc );
}
function addSWF(event : Event):void {
      event.target.removeEventListener(Event.COMPLETE, addSWF);
      event.target.removeEventListener(ProgressEvent.PROGRESS, preloadSWF);
      trace("Load Complete");
      this.percentTxt.visible = false;
      this.progress_mc.visible = false;
      _swfContent = event.target.content;
      this.addEventListener("close", unloadSWF);
      extContainer.addChild(_swfContent);
}

function unloadSWF(event : Event):void {
      _swfLoader.unloadAndStop();
      extContainer.removeChild(_swfContent);
      extContainer._swfContent = null;
}

For this to work, you'll need 2 movieclips, extContainer (this is where movieclips are loaded and you should place it where you want the external swf's should appear) and progress_mc (which is the preloader animation, and a dynamic textfield with an intance name of percentTxt, to see the progress numerically.

If you need more help, maybe you can send your fla so that I can take a look

Author

Commented:
ok, I tried adding the code you mentioned but my as3 has some similar code already and I couldn't get it to work. take a look at my project here...

 joeymerchant.com/project.zip.

open website.swf to see what I mean with slideshow.swf becoming out of scale. let me know when you have downloaded the zip. thanks!
Greetings,

I saw your code, in cleanslideshow.fla you are referring to stage.stageWidth and stage.stageHeight to fit  slideshow images upto full stage size.

But when you load a SWF in another SWF (AS3 version) then you'll get only parent's stage reference, so even if you are intended to use cleanslideshow.fla's stageWidth and stageHeight but at runtime it's using parent's (website_6-8-10.fla) stageWidth and stageHeight, and as a result it's covering full area of website swf.

To solve this situation you can make following changes in your cleanslideshow.fla
1. Fix the stageWidth and stageHeight in actionscript frame, on line # 29 and 30, fix as flows:
var stageWidth:Number = 569; // required width
var stageHeight:Number = 163; // required height

2. Remove the resizeEvent on line # 40, and clean remove the handler method [resizeListener]

Just compile this cleanslideshow.fla and you are good to go, no change required in website.fla.

Let me know if it helps or not.