Hi again!
I have two functions in C#:
public static string ToHexString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes) { sb.Append(b.ToString("X2")); }
return sb.ToString();
}
public static byte[] FromHexString(String hexString)
{
byte[] bytes = new byte[hexString.Length / 2];
for (int i = 0; i < bytes.Length; i++)
{
string hexByte = hexString.Substring(i * 2, 2);
bytes[i] = byte.Parse(hexByte, System.Globalization.NumberStyles.HexNumber);
}
return bytes;
}
When I test it in editor everything works fine.
When I try to export it as Flash I get the error:
Call to a possibly undefined method Parse_String_NumberStyles through a reference with static type Class.
In the corresponding Actionscript (.as) file which I can find in the Temp folder when trying to build in Flash I can see that the FromHexString function is transformed to this one:
public static function ComManagerScript_FromHexString_String($hexString: String): CLIByteArray {
var $array: CLIByteArray = CLIArrayFactory.NewByteArrayWithLength(int($hexString.length / 2));
for (var $i: int = 0; $i < $array.Length; $i = $i + 1) {
var $s: String = StringOperations2.String_Substring_Int32_Int32($hexString, $i * 2, 2);
$array.elements[$i] = int.Parse_String_NumberStyles($s, NumberStyles.HexNumber);
}
return $array;
}
I tried not to make the class static but the error remains.
It seems like there is a problem with the NumberStyles or some other incompatibility when trying to build the flash.
Just to mention that ToHexString function does not give me errors.
I use the latest Unity Pro (4.0.1) and I saw here:
http://unity3d.com/unity/preview/notes
that since 3.5 there is: Flash: Initial support for int.Parse(string, NumberStyles).
Any suggestions will be appreciated.
Thank you in advance.