PDA

View Full Version : Please Help me!How to load a swf file into an empty MC and preload it?



ecptavares
June 7th, 2007, 02:08 PM
Hi!

I got this code here at Kirupa.com and I use it to load the main page when a user first enters my web site.What if I wanted to use a preloader to preload each external swf File?How would I do it?How would I load a swf file into another empty movie clip?

can I make a class with this preload code so I can use it for any swf file or main movie?How?

The Code:



var request:URLRequest = new URLRequest("content.swf");
var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(Progress Event.PROGRESS, loadProgress);
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, loadComplete);

function loadProgress(event:ProgressEvent):void {
var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
trace("Loading: "+percentLoaded+"%");
}
function loadComplete(event:Event):void {
trace("Complete");
}

loader.load(request);
addChild(loader);

sasxa
June 7th, 2007, 08:51 PM
just create your class


package {
import flash.display.sprite;
public class MyClass extends Sprite {

}
}
put all that code in the constructor, and make functions private methods of your class... That way when you make new MyClass() you will get the object that has preloader(traces progress) & loader(traces complete)....

ecptavares
June 9th, 2007, 03:08 PM
Here is what I´ve done to my class. I have created some properties and in my flash movie I fill in this properties to be used in my class. What am I doing wrong?



package
{
import flash.display.MovieClip;
import flash.display.*;
import flash.text.TextField;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;

public class Carregador extends MovieClip
{

public var _Barra : MovieClip = new MovieClip();
public var _Texto : TextField = new TextField();
public var _Palco : MovieClip = new MovieClip();
public var _Movie : String;
public var loader:Loader = new Loader();

public function set Palco(value:MovieClip):void
{
_Palco = value;
}

public function set Barra(value:MovieClip):void
{
_Barra = value;
}

public function set Texto(value:TextField):void
{
_Texto = value;
}

public function set Movie(value:String):void
{
_Movie = value;
}

public function loadSwf():void
{
var request:URLRequest = new URLRequest(_Movie);

loader.contentLoaderInfo.addEventListener(Event.OP EN,showPreloader);
loader.contentLoaderInfo.addEventListener(Progress Event.PROGRESS, loadProgress);
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, loadComplete);

loader.load(request);
addChild(loader);

}

private function showPreloader(evt:Event):void
{
addChild(_Barra);
}

private function loadProgress(event:ProgressEvent):void
{
var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
_Barra.width = percentLoaded;
}

private function loadComplete(event:Event):void
{
removeChild(_Barra);
_Palco.addChild(_Movie);
}

}
}