Groups | Blog | Home
all groups > flash (macromedia) > july 2006 >

flash (macromedia) : loading swf into movieclip object


Barbidoll
7/30/2006 8:59:56 PM
I am trying to load a swf file into a movieclip object on the stage. The
movieclip object is sized smaller than the screen, and placed in the middle. I
have defined a loader with:
var myMovieClipLoader:MovieClipLoader = new MovieClipLoader();
then use it like this:
_level0.myMovieClipLoader.loadClip("moviename.swf",
_level5.movieclipinstancename);
(the movieclip object is used in a swf loaded in level5)

When I load the swf like this, the swf loads at the correct location according
to where I have placed the movieclip object, however it "blows up" to fill the
screen from that point down and across, ignoring the size of the movie clip
object (the loading swf actually expands beyond it's created size to fill the
screen, making all the graphics and text much larger than intended). The
actual pixel size of the swf I'm trying to load matches the size of the
movieclip object (1024x350 in a 1280x1024 screen).

What is the magic setting or property that will tell the loading swf to honor
the size of the movieclip object I'm loading into?

Thanks for your help!

Barb

nschubach
9/1/2006 2:33:58 PM
Something I've been working on:
Place the following code in a new file <your project
folder>\as\MovieContainer.as
Then open the properties for the symbol you want to be your movie container
Set the AS 2.0 Class to as.MovieContainer and give it a name (I named mine
'loader').
To load the movie, simply call:
loader.queueSWF('my.swf');

Hope that makes sense. Basically, it's just a self contained class for
loading into an object on the scene. It draws a simple progress bar on the
center of the symbol when it's loading and it resizes the loaded object on init
to conform to the size of the object on the stage. Why queueSWF? Well, if
it's currently loading a SWF, it will wait till it's finished and load a new
one. The biggest problem right now is the progress bar, but it's fairly easy
to remove if you don't like it. Hopefully it helps.

If anyone else is reading this. I'm trying to figure out if I can load these
movies into an array of movieclips. So far I've had no luck. If you know of a
way, feel free to drop some input.

//--------------------------------------------------------------------


import mx.utils.Delegate;

class as.MovieContainer extends MovieClip{
private var queue:Array;
private var loading:Boolean;
private var file:String;
private var loader:MovieClipLoader;
private var listener:Object;
private var progress:MovieClip;
private var progressText:TextField;
private var container:MovieClip;
private var hold:Array;
private var mask:MovieClip;
private var holdWidth:Number;
private var holdHeight:Number;

public function MovieContainer (file:String) {
if (file) loadSWF(file);
trace('Creating: ' + this);
loader = new MovieClipLoader();
queue = new Array();
hold = new Array();
listener = new Object;
listener.onLoadProgress = Delegate.create(this, onLoadProgress);
listener.onLoadComplete = Delegate.create(this, onLoadComplete);
listener.onLoadInit = Delegate.create(this, onLoadInit);
loader.addListener(listener);
progress = new MovieClip();
progressText = new TextField();
container = new MovieClip();
container = this.createEmptyMovieClip('container',
this.getNextHighestDepth());
mask = this.duplicateMovieClip(this._name + '_mask',
this.getNextHighestDepth());
this.setMask(mask);
holdWidth = Math.round(this._width);
holdHeight = Math.round(this._height);
loading = false;
}

private function onLoadInit(mc:MovieClip):Void {
trace('Initialized: ' + mc);
var xScale = Math.round((holdWidth / this._width) * 100);
var yScale = Math.round((holdHeight / this._height) * 100);
if (xScale <> 100) mc._xscale = xScale;
if (yScale <> 100) mc._yscale = yScale;
progress.removeMovieClip();
progressText.removeTextField();
if (queue.length > 0) {
loadSWF();
}
}

private function onLoadComplete(mc:MovieClip):Void {
trace('Loaded into: ' + mc);
}

private function onLoadProgress(mc:MovieClip, bytesLoaded:Number,
bytesTotal:Number):Void {
var prct = (bytesLoaded / bytesTotal);
var txtHeight = progressText._height;
progress._x = (this._width / 3);
progress._y = (this._height / 2) - (txtHeight / 2);
progress._width = (this._width / 3) * prct;
progress._height = txtHeight;
progressText.text = Math.round(prct * 100) + '%';
progressText.thickness = 2;
progressText._x = progress._x + progress._width - progressText._width;
progressText._y = progress._y;
}

public function queueSWF(file:String) {
queue.push(file);
if (!loading) loadSWF();
}

public function loadSWF() {
loading = true;
var file = queue.shift().toString();
if (!file) return;
trace('Load: ' + file);
progress = this.createEmptyMovieClip('progress', this.getNextHighestDepth());
progressText = this.createTextField('progressText',
this.getNextHighestDepth(), 0, 0, 20, 20);
progressText.autoSize = true;
progressText.textColor = 0xFFFFFF;
progressText.text = '0%';
progress._width = 0;
progress.beginGradientFill('linear', [0x000000, 0x000033], [10, 100], [0,
255], {matrixType:"box", x:0, y:0, w:_parent._width, h:_parent._height, r:0});
progress.moveTo(0, 0);
progress.lineTo(this._width, 0);
progress.lineTo(this._width, this._height);
progress.lineTo(0, this._height);
progress.endFill();
loader.loadClip(file, container);
}
}
nschubach
9/1/2006 2:38:39 PM
oops, I just realized that's the version without the reset for 'loading'

Just replace the onLoadInit function with this:

private function onLoadInit(mc:MovieClip):Void {
trace('Initialized: ' + mc);
var xScale = Math.round((holdWidth / this._width) * 100);
var yScale = Math.round((holdHeight / this._height) * 100);
if (xScale <> 100) mc._xscale = xScale;
if (yScale <> 100) mc._yscale = yScale;
progress.removeMovieClip();
progressText.removeTextField();
if (queue.length > 0) {
loadSWF();
} else {
loading = false;
}
}
AddThis Social Bookmark Button