Skip to content

Instantly share code, notes, and snippets.

@Scrivener07
Created May 22, 2018 04:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Scrivener07/542c860fe81f09d757dbfde1b45b5627 to your computer and use it in GitHub Desktop.
Save Scrivener07/542c860fe81f09d757dbfde1b45b5627 to your computer and use it in GitHub Desktop.
F4SE for loading DDS images into scaleform.
package
{
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
public dynamic class OverlayLoader extends MovieClip
{
private var Content:DisplayObject;
private var ContentLoader:Loader;
public function get Info() : LoaderInfo { return ContentLoader.contentLoaderInfo; }
public function get FilePath() : String { return ContentLoader.contentLoaderInfo.url; }
public function get Instance() : String { return Utility.WalkMovieFrom(Content, this); }
// Initialize
//---------------------------------------------
public function OverlayLoader()
{
super();
this.visible = false;
Content = null;
ContentLoader = new Loader();
ContentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.OnLoadComplete);
ContentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.OnLoadError);
}
// Methods
//---------------------------------------------
public function Load(filePath:String) : void
{
ContentLoader.close();
if (Content)
{
Unload();
}
var urlRequest:URLRequest = new URLRequest(filePath);
ContentLoader.load(urlRequest);
}
public function Unload() : Boolean
{
if (Content)
{
this.visible = false;
removeChild(Content);
Content.loaderInfo.loader.unload();
return true;
}
else
{
return false;
}
}
// Events
//---------------------------------------------
private function OnLoadComplete(e:Event) : void
{
Content = e.currentTarget.content;
addChild(Content);
this.visible = true;
}
private function OnLoadError(e:IOErrorEvent) : void
{
this.visible = false;
}
}
}
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.IOErrorEvent;
public class OverlayMenu extends MovieClip
{
public var Overlay:OverlayLoader;
public function get Visible():Boolean { return this.visible; }
public function set Visible(argument:Boolean):void { this.visible = argument; }
public function OverlayMenu()
{
Debug.Log("OverlayMenu", "ctor", "Constructor Code");
}
public function onF4SECodeObjCreated(codeObject:Object) : *
{
trace("OverlayMenu onF4SECodeObjCreated");
codeObject.MountImage("OverlayMenu", "Textures\\HaloOverlay.dds", "OverlayImage");
}
// Functions
//---------------------------------------------
public function SetOverlay(filepath:String) : *
{
filepath = "img://OverlayImage";
// filepath = ConvertFileExtension(filepath, "swf");
Overlay.Info.addEventListener(Event.COMPLETE, this.OnLoadComplete);
Overlay.Info.addEventListener(IOErrorEvent.IO_ERROR, this.OnLoadError);
Overlay.Load(filepath);
Debug.Log("OverlayMenu", "SetOverlay", "Setting the overlay file path to '"+filepath+"'.");
}
private function ConvertFileExtension(filepath:String, toExtension:String) : String
{
var converted = Path.ConvertFileExtension(filepath, toExtension);
Debug.Log("OverlayMenu", "ConvertFileExtension", "Converting file path '"+filepath+"' to '"+toExtension+"' extension as '"+converted+"'.");
return converted;
}
// Events
//---------------------------------------------
private function OnLoadComplete(e:Event) : void
{
Overlay.Info.removeEventListener(Event.COMPLETE, this.OnLoadComplete);
Overlay.Info.removeEventListener(IOErrorEvent.IO_ERROR, this.OnLoadError);
Debug.Log("OverlayMenu", "OnLoadComplete", "Override found at '"+Overlay.FilePath+"' with instance of '"+Overlay.Instance+"'.");
}
private function OnLoadError(e:IOErrorEvent) : void
{
Overlay.Info.removeEventListener(Event.COMPLETE, this.OnLoadComplete);
Overlay.Info.removeEventListener(IOErrorEvent.IO_ERROR, this.OnLoadError);
Debug.Log("OverlayMenu", "OnLoadError", "No override found at '"+Overlay.FilePath+"'.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment