ok if you want a better way to load pngs inside your scaleform is by doing this
- First of all… add an empty movie clip inside your project and call it txdLoader
like this
the class you wanna link is com.rockstargames.ui.media.ImageLoaderMC
- Then in your script in the MAIN.as file of your project add these 3 public functions
function ADD_TXD_REF_RESPONSE(txd, strRef, success)
{
com.rockstargames.ui.utils.Debug.log("ADD_TXD_REF_RESPONSE - " + arguments.toString());
if (success == true)
{
var pMC = this.CONTENT;
var il = com.rockstargames.ui.media.ImageLoaderMC(eval(pMC + "." + strRef));
if (pMC != undefined)
{
il.displayTxdResponse(txd);
}
}
}
function TXD_HAS_LOADED(txd, success, strRef)
{
com.rockstargames.ui.utils.Debug.log("TXD_HAS_LOADED - " + arguments.toString());
if (success == true)
{
var pMC = this.CONTENT;
var il = com.rockstargames.ui.media.ImageLoaderMC(eval(pMC + "." + strRef));
if (pMC != undefined)
{
il.displayTxdResponse(txd,success);
}
}
}
function TXD_ALREADY_LOADED(txd, strRef)
{
com.rockstargames.ui.utils.Debug.log("TXD_ALREADY_LOADED - " + arguments.toString());
var pMC = this.CONTENT;
var il = com.rockstargames.ui.media.ImageLoaderMC(eval(pMC + "." + strRef));
if (pMC != undefined)
{
il.displayTxdResponse(txd,true);
}
}
-
Then use the attachMovie() function to add the txdLoader in your code wherever you want…
-
When you want to load any txd, txn (DUI or ingame or streamed) use this function around your code to dynamically load your txd-txn via scaleform natives
function SetClip(targetMC, textureDict, textureName, w, h, callback, scope)
{
var alreadyLoaded = true;
if (targetMC.textureFilename != textureName && targetMC.textureDict != textureDict)
{
var alreadyLoaded = false;
}
targetMC.init("YOUR-GFX-NAME",textureDict,textureName,w,h);
var splitPath = String(targetMC).split(".");
var pathWithoutContent = splitPath.slice(2).join(".");
com.rockstargames.ui.tweenStar.TweenStarLite.removeTweenOf(targetMC);
targetMC._alpha = 100;
targetMC.requestTxdRef(pathWithoutContent,alreadyLoaded,callback,scope);
}
I made the function SetClip to dynamically load any texture without the need to Load it before via natives… the scaleform will load it and draw it for you…
SetClip has these parameters:
- targetMC: the txdLoader movieClip you reference
- textureDict: the texture dictionary (runtime, dui, ingame, streamed… who cares)
- textureName: the name of the texture to load
- w, h: width and height of the texture you wanna draw
- callback: any function you wanna call whenever the load is finished (optional)
- scope: i usually use “this” to reference all the class i’m using… for example if i’m drawing a badge in ScaleformUI inside a UIMenuItem i reference
this
as the whole UIMenuItem isntance inside the function (that’s how flash works )
example:
– this function is called inside UIMenuItem in NativeUI-scaleform_flash in my github
function SetLeftBadge(id)
{
this.leftBadgeId = id;
if (this.leftBadgeId != com.rockstargames.ScaleformUI.utils.Badges.NONE)
{
if (this.leftBadgeMC.isLoaded)
{
this.leftBadgeMC.removeMovieClip();
}
this.leftBadgeMC = this.itemMC.attachMovie("txdLoader", "LeftBadge", this.itemMC.getNextHighestDepth());
var sprite_name = com.rockstargames.ScaleformUI.utils.Badges.getSpriteNameById(id, this.highlighted);
var sprite_txd = com.rockstargames.ScaleformUI.utils.Badges.GetSpriteDictionary(id);
SetClip(this.leftBadgeMC,sprite_txd,sprite_name,24,24,this.leftBadgeLoaded,this);
this.itemMC.labelMC._x = 28.25;
}
else
{
if (this.leftBadgeMC.isLoaded)
{
this.leftBadgeMC.removeTxdRef();
this.leftBadgeMC.removeMovieClip();
this.itemMC.labelMC._x = 5;
}
}
this.updateLabelWidth();
}
function leftBadgeLoaded()
{
this.leftBadgeMC._visible = true;
this.leftBadgeMC._width = 24;
this.leftBadgeMC._height = 24;
this.leftBadgeMC._x = 0.5;
this.leftBadgeMC._y = 0.5;
this.updateLabelWidth();
}