132 posts
  • Affiliate Level 2
  • Author Level 6
  • Beta Tester
  • Collector Level 2
+3 more
baklach
says

Hi guys,

Well, how do i convert datatype from xml to an other, String, Number, Boolean, etc. using the values of the variables? like if the value is “0xFFFFFF”, convert it to number or if the value is “true”/”false” convert it to boolean. The problem is that all the values are stored in Objects dynamically from xml file, so values are xml. Is there any method to do so, or i need to improvise ? :) oh, and this all in AS3 .

Thanks a lot! I really appreciate your help!

7 posts
  • 5 Years of Membership
  • Author Level 3
  • Collector Level 1
  • Exclusive Author
+2 more
daveash
says

Parsing a string like “HelloWorld” with parseFloat and parseInt will give you NaN so using the isNaN() condition would be a good idea. However, parsing a hex value like “0xff9933” with parseFloat will give you “0” while using parseInt will give you “16750899”.

I hope this info helps a bit.

1829 posts Time is what you desire most, but waste carelessly.
  • Author Level 9
  • Elite Author
  • Exclusive Author
  • Trendsetter
+9 more
Firsh
says

table.settings.color = "0x"+String(table.settings.color);

then they just set the 6 digits in the xml.. :)

4140 posts
  • 7 Years of Membership
  • Affiliate Level 1
  • Author Level 4
  • Brazil
+5 more
tsafi
says
Hi guys,

Well, how do i convert datatype from xml to an other, String, Number, Boolean, etc. using the values of the variables? like if the value is “0xFFFFFF”, convert it to number or if the value is “true”/”false” convert it to boolean. The problem is that all the values are stored in Objects dynamically from xml file, so values are xml. Is there any method to do so, or i need to improvise ? :) oh, and this all in AS3 .

Thanks a lot! I really appreciate your help!
Instead to type it each time just add this simple helper class
package com.StudioTsafi.utils{
    public class Col {

    public static function Hex(_Hex:String):int {
        var _ColorTo:String="0x"+_Hex.substr(1,_Hex.length);return int(_ColorTo);
        }

    }
}
How to call it ?,very simple lets say you whant to use the hex in your xml so
yourObjectColor          = Col.Hex(xml.copyright.@color);

in the xml

<copyright color="#ff0000" />

and thanks for buying :P

132 posts
  • Affiliate Level 2
  • Author Level 6
  • Beta Tester
  • Collector Level 2
+3 more
baklach
says

Thanks guys! These will definitely help in finding the solution. Time for Plan B :) improvisation. Need to make a class to parse the values and return the datatype of the variables. Will post the solution here if anyone will need it.

Thanks!

7 posts
  • 5 Years of Membership
  • Author Level 3
  • Collector Level 1
  • Exclusive Author
+2 more
daveash
says

Here’s my solution. First, parse the value as a string. Then extract the two first characters of that string. If the first character is # or the first two are 0x then parse as color. If non of these conditions hold true, determine whether the string matches “true” or “false”. If not, then parse the string as a float value. Lastly, if the parseFloat method returns NaN, you know the value is of type String.

If you’re having trouble translating this into actual code i’ll help you.

132 posts
  • Affiliate Level 2
  • Author Level 6
  • Beta Tester
  • Collector Level 2
+3 more
baklach
says
Here’s my solution. First, parse the value as a string. Then extract the two first characters of that string. If the first character is # or the first two are 0x then parse as color. If non of these conditions hold true, determine whether the string matches “true” or “false”. If not, then parse the string as a float value. Lastly, if the parseFloat method returns NaN, you know the value is of type String. If you’re having trouble translating this into actual code i’ll help you.

Coding is not a problem, in fact i love to code, especially in AS3 ;) Thanks a lot daveash!

7 posts
  • 5 Years of Membership
  • Author Level 3
  • Collector Level 1
  • Exclusive Author
+2 more
daveash
says
Here’s my solution. First, parse the value as a string. Then extract the two first characters of that string. If the first character is # or the first two are 0x then parse as color. If non of these conditions hold true, determine whether the string matches “true” or “false”. If not, then parse the string as a float value. Lastly, if the parseFloat method returns NaN, you know the value is of type String. If you’re having trouble translating this into actual code i’ll help you.
Coding is not a problem, in fact i love to code, especially in AS3 ;) Thanks a lot daveash!

Glad i could help!

132 posts
  • Affiliate Level 2
  • Author Level 6
  • Beta Tester
  • Collector Level 2
+3 more
baklach
says

Here is the solution i made in case if anyone need it.

http://pastie.org/1174262

oh and the..

import com.teelt.utilities.parse;

var val:String = "true";
trace(typeof(parse.value(val)));
trace(parse.value(val));
132 posts
  • Affiliate Level 2
  • Author Level 6
  • Beta Tester
  • Collector Level 2
+3 more
baklach
says
by
by
by
by
by
by