I’m making a button class to which I want to apply a font. With the code I have now, once the font is loaded, my text disappears…
Here below are the two scripts… Hopefully you guys can help!
Button Class:
package net.[COLOR=#000000]ui[/COLOR].[COLOR=#000000]buttons[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]display[/COLOR].[COLOR=#993300]MovieClip[/COLOR];
[COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]display[/COLOR].[COLOR=#000000]Loader[/COLOR];
[COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]net[/COLOR].[COLOR=#000000]URLRequest[/COLOR];
[COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]net[/COLOR].[COLOR=#000000]URLLoader[/COLOR];
[COLOR=#993300]import[/COLOR] flash.[COLOR=#993300]system[/COLOR].[COLOR=#000000]ApplicationDomain[/COLOR];
[COLOR=#993300]import[/COLOR] flash.[COLOR=#993300]text[/COLOR].[COLOR=#000000]AntiAliasType[/COLOR];
[COLOR=#993300]import[/COLOR] flash.[COLOR=#993300]text[/COLOR].[COLOR=#993300]TextField[/COLOR];
[COLOR=#993300]import[/COLOR] flash.[COLOR=#993300]text[/COLOR].[COLOR=#993300]TextFormat[/COLOR];
[COLOR=#993300]import[/COLOR] flash.[COLOR=#993300]text[/COLOR].[COLOR=#993300]Font[/COLOR];
[COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]events[/COLOR].*;
[COLOR=#993300]import[/COLOR] gs.[COLOR=#000000]TweenMax[/COLOR];
[COLOR=#993300]import[/COLOR] gs.[COLOR=#000000]easing[/COLOR].*;
[COLOR=#993300]public[/COLOR] [COLOR=#993300]class[/COLOR] GlowButton [COLOR=#993300]extends[/COLOR] [COLOR=#993300]MovieClip[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]private[/COLOR] [COLOR=#993300]var[/COLOR] _bouton:[COLOR=#993300]MovieClip[/COLOR];
[COLOR=#993300]private[/COLOR] [COLOR=#993300]var[/COLOR] _legende:[COLOR=#993300]TextField[/COLOR];
[COLOR=#993300]private[/COLOR] [COLOR=#993300]var[/COLOR] _pLegende:[COLOR=#993300]String[/COLOR];
[COLOR=#993300]private[/COLOR] [COLOR=#993300]var[/COLOR] glowTween:TweenMax;
[COLOR=#993300]private[/COLOR] [COLOR=#993300]var[/COLOR] colorTween:TweenMax; [COLOR=#993300]private[/COLOR] [COLOR=#993300]var[/COLOR] _format:[COLOR=#993300]TextFormat[/COLOR];
[COLOR=#993300]private[/COLOR] [COLOR=#993300]var[/COLOR] loader:Loader;
[COLOR=#993300]public[/COLOR] [COLOR=#993300]function[/COLOR] GlowButton[COLOR=#000000]([/COLOR]pCouleur:[COLOR=#993300]Number[/COLOR], pLegende:[COLOR=#993300]String[/COLOR]=[COLOR=#0000ff]"Button Text"[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
_pLegende = pLegende;
_bouton = [COLOR=#993300]new[/COLOR] [COLOR=#993300]MovieClip[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
addChild[COLOR=#000000]([/COLOR]_bouton[COLOR=#000000])[/COLOR];
_bouton.[COLOR=#000000]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000000]ROLL_OVER[/COLOR], survol[COLOR=#000000])[/COLOR];
_bouton.[COLOR=#000000]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000000]ROLL_OUT[/COLOR], sortie[COLOR=#000000])[/COLOR];
_legende = [COLOR=#993300]new[/COLOR] [COLOR=#993300]TextField[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
_legende.[COLOR=#993300]selectable[/COLOR] = [COLOR=#993300]false[/COLOR];
_legende.[COLOR=#993300]text[/COLOR] = pLegende;
_legende.[COLOR=#993300]textColor[/COLOR] = pCouleur;
_bouton.[COLOR=#000000]addChild[/COLOR][COLOR=#000000]([/COLOR]_legende[COLOR=#000000])[/COLOR];
_bouton.[COLOR=#000000]buttonMode[/COLOR] = [COLOR=#993300]true[/COLOR];
_bouton.[COLOR=#000000]mouseChildren[/COLOR] = [COLOR=#993300]false[/COLOR];
applyFont[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]private[/COLOR] [COLOR=#993300]function[/COLOR] survol[COLOR=#000000]([/COLOR]event:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR] [COLOR=#000000]{[/COLOR]
glowTween = TweenMax.[COLOR=#000000]to[/COLOR][COLOR=#000000]([/COLOR]_bouton, [COLOR=#000000]1[/COLOR], [COLOR=#000000]{[/COLOR]glowFilter: [COLOR=#000000]{[/COLOR][COLOR=#993300]color[/COLOR]:0xffffff, alpha:[COLOR=#000000]1[/COLOR] , blurX:[COLOR=#000000]10[/COLOR], blurY:[COLOR=#000000]10[/COLOR], strength:[COLOR=#000000]3[/COLOR], [COLOR=#993300]quality[/COLOR]:[COLOR=#000000]3[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];
colorTween = TweenMax.[COLOR=#000000]to[/COLOR][COLOR=#000000]([/COLOR]_legende, [COLOR=#000000]1[/COLOR],[COLOR=#000000]{[/COLOR]hexColors: [COLOR=#000000]{[/COLOR][COLOR=#993300]textColor[/COLOR]:0xffffff[COLOR=#000000]}[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]private[/COLOR] [COLOR=#993300]function[/COLOR] sortie[COLOR=#000000]([/COLOR]event:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR] [COLOR=#000000]{[/COLOR]
glowTween.[COLOR=#993300]reverse[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
colorTween.[COLOR=#993300]reverse[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]function[/COLOR] applyFont[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
loader = [COLOR=#993300]new[/COLOR] Loader[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
loader.[COLOR=#000000]contentLoaderInfo[/COLOR].[COLOR=#000000]addEventListener[/COLOR][COLOR=#000000]([/COLOR]Event.[COLOR=#000000]COMPLETE[/COLOR], fontCompleteHandler[COLOR=#000000])[/COLOR];
loader.[COLOR=#993300]load[/COLOR][COLOR=#000000]([/COLOR][COLOR=#993300]new[/COLOR] URLRequest[COLOR=#000000]([/COLOR][COLOR=#0000ff]"lib/fontLibrary.swf"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]function[/COLOR] fontCompleteHandler[COLOR=#000000]([/COLOR]event:Event[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]var[/COLOR] [COLOR=#993300]domain[/COLOR]:ApplicationDomain = loader.[COLOR=#000000]contentLoaderInfo[/COLOR].[COLOR=#000000]applicationDomain[/COLOR];
[COLOR=#993300]var[/COLOR] [COLOR=#993300]font[/COLOR]:[COLOR=#993300]Class[/COLOR] = [COLOR=#993300]domain[/COLOR].[COLOR=#000000]getDefinition[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]"LastUniform"[/COLOR][COLOR=#000000])[/COLOR] as [COLOR=#993300]Class[/COLOR];
[COLOR=#993300]Font[/COLOR].[COLOR=#000000]registerFont[/COLOR][COLOR=#000000]([/COLOR][COLOR=#993300]font[/COLOR][COLOR=#000000])[/COLOR];
initStyles[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]function[/COLOR] initStyles[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]var[/COLOR] tf:[COLOR=#993300]TextFormat[/COLOR] = [COLOR=#993300]new[/COLOR] [COLOR=#993300]TextFormat[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]"LastUniform"[/COLOR],[COLOR=#000000]12[/COLOR],0x000000[COLOR=#000000])[/COLOR];
_legende.[COLOR=#993300]embedFonts[/COLOR] = [COLOR=#993300]true[/COLOR];
_legende.[COLOR=#000000]antiAliasType[/COLOR] = AntiAliasType.[COLOR=#000000]ADVANCED[/COLOR];
_legende.[COLOR=#993300]setTextFormat[/COLOR][COLOR=#000000]([/COLOR]tf[COLOR=#000000])[/COLOR];
[COLOR=#993300]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]"font applied"[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
TestButton AS File:
package [COLOR=#000000]{[/COLOR]
[COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]display[/COLOR].[COLOR=#993300]MovieClip[/COLOR];
[COLOR=#993300]import[/COLOR] net.[COLOR=#000000]ui[/COLOR].[COLOR=#000000]buttons[/COLOR].[COLOR=#000000]GlowButton[/COLOR]; [COLOR=#993300]public[/COLOR] [COLOR=#993300]class[/COLOR] boutonTest [COLOR=#993300]extends[/COLOR] [COLOR=#993300]MovieClip[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]public[/COLOR] [COLOR=#993300]function[/COLOR] boutonTest[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]var[/COLOR] firstButton:GlowButton = [COLOR=#993300]new[/COLOR] GlowButton[COLOR=#000000]([/COLOR]0x000000, [COLOR=#0000ff]"Some Text"[/COLOR][COLOR=#000000])[/COLOR];
addChild[COLOR=#000000]([/COLOR]firstButton[COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]