[swx] mtasc strict

Udvari Gábor udi86 at citromail.hu
Sat Jul 21 23:52:57 EDT 2007


It's me again :),



after looking at the original JSON actionscript code at json.org, I got an 
idea that we could use a switch in swx.as to solve the strict type checking
 in mtasc. Instead of this code:



var x = data[i];

// Note: check for Array first since everything is an Object.

if (x instanceof Array){

    arrayToJson(x);

}else if (x instanceof Object){

    objectToJson(x);

}else if (typeof x == "string"){

    stringToJson(x);

}else{

    // Other simple data type, add as-is

    json += x;

}



we could use this one:



switch (typeof data[i]) {

  case 'Array': arrayToJson(pata[i]);

  case 'Object': objectToJson(data[i]);

  case 'String': stringToJson(data[i]);

  default: json += data[i];

}



The above code is in swx.as at line 293 and 340. Aral, please check if some
thing is wrong with the switch structure. I've tested it, but who knows. Th
e switch is cleaner and mtasc -strict compatible ;).



Another change in the swx.as file, at line 432 there is a variable redifini
tion:



var c = c.charCodeAt();

json += '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16)
;



c was before declared as a String, so another variable should be introduced
, I used cN because it will be a Number. My suggestion to the code:



var cN:Number = c.charCodeAt();

json += '\\u00' + Math.floor(cN / 16).toString(16) + (cN % 16).toString(1
6);



Another changes I made at home were patching the mx classes to version 1.1.
 I found an article about it on osflash.org, another thanks for that site t
oo ;), and after that I had to change the EventDispatcher.as file too, in o
rder that it compiles with mtasc -strict, but it was just adding the types.



After these changes the SWX Full API seems to work, but now with mtasc -str
ict, which was my dream :D. Please Aral, check my changes, I can send the f
iles if needed, but it would be really cool if the next release of the API 
would be mtasc strict compatible.



Happy coding: Udi



_________________________________________

Éhes vagy? Internetes ételrendelés, egyszerűen, házhozszállít
ással! Pizzák, hamburgerek, saláták, stb.... Minden egy helyen! KLI
KK IDE!



More information about the swx mailing list