[swx] Problem saving swx returned object
holger arndt
holger.arndt at synap.de
Fri Apr 25 02:03:05 PDT 2008
You're welcome,
that was indeed an interesting problem.
And in short about the two functions typeof and instanceof:
typeof returns the main type of a variable as a string. Its value is
limited to basic types: object,movieclip,string,number,boolean
instanceof can only check if an object was constructed using a
specific function (i.e. class constructor)
so "x instanceof yourClassName" will return true, if x is a direct
instance or an extension of yourClassName
So the point is (i think), that the result property was not
constructed by actionscript but was directly transformed into bytecode
by the SWX assembler. Therefore it lacks the constructor property that
indicates that it is an Object. But it has all the other properties
that you added to it, hence you can access your properties without any
problem.
And i don't think that there are any sideeffects when changing the two
functions.
You should probably change all "x instanceof Object" to the typeof
style (i.e. in function objectToJson) to make sure your objects in an
object get converted as well...but don't change instanceof Array
because array is not a basic type and typeof will return "object" as
well
Am 25.04.2008 um 00:46 schrieb Nederflash (Folkert Hielema):
> nice one
>
> holger arndt wrote:
>> Hi Robert,
>> as you can read below, i have worked on that problem a while
>> and found a clue to what the problem might be.
>>
>> And i have found a radical solution :-)
>>
>> So the object that is returned to a SWXcallback is an Object but the
>> result property is not...or better no quite :-)
>> To Flash it is an object because typeof(e.result) rturns the String
>> "object"
>> But when using strict typing, as you can read below, e.result is NOT
>> an Object
>> And the instanceof function also returns false...
>>
>> So what to do...?
>> go into the class org.swxformat.SWX
>> and find the function "arrayToJson"
>> this is called for preparing the args-Array.
>> Within it you will find that Aral used the
>> "x instanceof Object"
>> function to see if a parameter is indeed an Object
>> when you change this to
>> typeof x = "object"
>> it works fine and you can send resultObjects directly as args again
>>
>> So before you jump ahead, i want you to notice that you change
>> sourceCode that's not yours.
>> OK, now go ahead ;-)
>>
>>
>> Greets,
>> Holger Arndt
>>
>>
>>
>> ************EARLIER**************
>> so far I can only confirm that there is indeed a problem with using
>> the result object of SWX.call as an argument
>> within the result handler.
>> i constructed a simple call to a method like yours on the server
>> side,
>> which only returns the object itself
>> and just used the result property as the args parameter for the
>> second
>> call to just the same method and it returns null.
>> So I'm trying to figure out, what the problem is but it seems that
>> it's noting special to your script...
>>
>> A clue to the problem might be that e.result is not seen as an Object
>> in Flash (see below):
>>
>> var example = {name:"senseless"};
>> trace(example.constructor==Object);//true
>>
>> But in the callback function:
>> function resultHandlerFromSwx(e:Object){
>> trace(e.constructor==Object); //true
>> trace(e.result.constructor==Object); //false
>> }
>>
>> And when pass the result property directly to a function that
>> strictly
>> accepts only Objects, i get a compiler error...
>>
>> function resultHandlerOne(e:Object){
>> echo(e.result);
>> }
>> function echo(result:Object){
>> //error : type mismatch
>> }
>>
>> If i use strict typing to MovieClip, it passes without error...
>> ******************************************
>>
>> I HAD TO CANCEL THE REST OF THE MESSAGES OR THE MAILER WOULDNT ACCEPT
>> IT....
>>
>> _______________________________________________
>> swx mailing list
>> swx at osflash.org
>> http://osflash.org/mailman/listinfo/swx_osflash.org
>>
>>
>
>
> _______________________________________________
> swx mailing list
> swx at osflash.org
> http://osflash.org/mailman/listinfo/swx_osflash.org
More information about the swx
mailing list