Nit*_*hil 1 apache-flex actionscript-3 flash-builder
如何在flex中将int类型转换为8位十六进制十进制数
我需要一个类似于c#[ToString("X8")]的函数.此函数在c#中完成工作.但是flex中的选项是什么?
如文档中所述,它几乎相同:
var myInt:int = 255;
var hex:String = myInt.toString(16);
trace(hex); //outputs "ff"
Run Code Online (Sandbox Code Playgroud)
请参阅http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/int.html#toString()
如果您正在使用它的颜色:文档也描述了如何处理该案例.
但是没有内置的方法来添加前导零.你可以使用像这样的方法来做到这一点:
public function pad(s:String, pattern:String="0", minChars:int=8):String {
while (s.length < minChars) s = pattern + s;
return s;
}
trace(pad(hex)); //000000ff
Run Code Online (Sandbox Code Playgroud)