132 posts
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 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
  • Has been part of the Envato Community for over 4 years
  • Has sold $1,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+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.

1716 posts Time is what you desire most, but waste carelessly.
  • Has sold $125,000+ on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
+6 more
Firsh says

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

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

4140 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Located in Brazil
+3 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
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 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
  • Has been part of the Envato Community for over 4 years
  • Has sold $1,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+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
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 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
  • Has been part of the Envato Community for over 4 years
  • Has sold $1,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+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
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 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
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 more
baklach says
by
by
by
by
by
by