1
때때로 다른 프리 로더를 사용하고자하는 프로젝트를 가지고 있으므로 외부 프로젝트를 사용할 수있는 방법이 있는지 알고 싶었습니다. 프리 로더?플래시의 프리 로더로 외부 swf를 사용하는 방법
때때로 다른 프리 로더를 사용하고자하는 프로젝트를 가지고 있으므로 외부 프로젝트를 사용할 수있는 방법이 있는지 알고 싶었습니다. 프리 로더?플래시의 프리 로더로 외부 swf를 사용하는 방법
절대적으로, 실제로 이것은 매우 일반적인 관행입니다.
외부 프리 로더 파일은 Loader 클래스의 인스턴스를 인스턴스화하고 페이로드 .swf를로드하면됩니다. 페이로드가로드되는 동안 ProgressEvent.PROGRESS를 수신하고이를 사용하여 일종의로드 막대 또는 기타를 업데이트 할 수 있습니다. 다음과 같이 보일 것입니다 :
package
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
public class Preloader extends MovieClip
{
// this loads in your main swf
public var loader:Loader;
// this points to the location of your main swf
public var request:URLRequest;
// this holds a reference to your main swf once it's been loaded in.
public var content:MovieClip;
public function Preloader()
{
addEventListener(Event.ADDED_TO_STAGE, addedHandler);
super();
}
// it's a good practice to wait for ADDED_TO_STAGE before you start doing stuff, that way you can avoid certain Null Reference Errors
protected function addedHandler(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, addedHandler);
loader = new Loader();
request = new URLRequest("path/to/your/file.swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
}
// This will fire when your main swf is loaded in.
protected function completeHandler(e:Event):void {
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHandler);
loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, errorHandler);
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
trace("Load completed! Now we're going to add the target swf to the timeline:");
content = MovieClip(loader.content);
/*
* Additional logic can go here to remove your loadbar or etc.
*/
}
// this will fire if there's a problem with loading in the swf
protected function errorHandler(e:IOErrorEvent):void {
trace("Error: the path specified was incorrect. Unable to find that file. Here's the error in full:\n " + e)
}
// this will fire constantly while the target swf is being loaded, so you can see how much more you have to load.
protected function progressHandler(e:ProgressEvent):void {
var perLoaded:Number = 100* (e.bytesLoaded/e.bytesTotal)
trace("Percent Loaded: " + perLoaded);
/*
* Additional logic can go here to update your load bar, etc.
*/
}
}
}
이것이 올바른 접근 방식인지는 확실하지 않습니다. 플래시 프로젝트 나는 벌써 다른 로딩 할 때까지 회전하는 로더를 가지고있다. 다음 로딩은 프리 로더가 존재하지 않거나 존재하지만 멈추는 다음 프레임으로 간다. 그래서 나는 그저 외부의 aminmation을로드하고 애니메이션이 멈추거나 사라지도록 만들고 싶습니다. 다른 모든 것이로드 될 때 사라집니다. – mcgrailm
아, 알았습니다. 좀 더 복잡합니다. 즉석에서 로더 클래스를 생성하기 위해 일종의 팩토리 패턴을 사용할 수 있습니다.하지만 프레임 1/프레임 2 내보내기 트릭을 수행하는 경우 작동하는지 확실하지 않습니다. . 짧은 대답 : 가능하지만 프로젝트가 설정되는 방식에 따라 약간의 변화가있을 수 있습니다. – Myk