Link to home
Start Free TrialLog in
Avatar of merchantweb
merchantweb

asked on

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!
Avatar of zeeshanashraf
zeeshanashraf

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

it should help
Avatar of merchantweb

ASKER

I would but I don't know how... Thanks!
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
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!
ASKER CERTIFIED SOLUTION
Avatar of ActionScript_Helper
ActionScript_Helper
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial