views:

443

answers:

3

Having used FlashDevelop with a project, and switched to FDT/Eclipse. I am sorting through hundreds of warnings in my code.

Quite a few relate to XML and JSON syntax this project is using. In the following, I'm not sure what to cast the XML containing data as so that it is recognised by the compiler

Example:

public function convertXMLToAssets(file:XML):void
{
    var data:XML = new XML(file.data);
    var id:int = data.item.id;
    //etc
}

//gives Warning: Could not resolve variable (may be a dynamic member) data at line 59
A: 

Well since everything in E4X is either XML objects or strings, I highly doubt that data.item[i].id can be a number. If the ID is a float, use parseFloat(data.item[i].id) and if it's just an int use +data.item[i].id.

Edit: Is there more than one <item/>? If so, I think you want data..item[0].id. Here's some stuff I think you may want to try:

  • data..item[0].id
  • data..item[0].@id
  • data.id
  • data.@id
Eli Grey
If I parse or cast the float/int/Number the "item" is still not a recognised resolvable variable and is throwing a warning (using FDT/Eclipse only)
cb
@cat-biscuit: Can you edit your original post to show what the error is if you attempt to do the parse/cast?
Raul Agrait
+1  A: 

file:String doesn't have a "data" property (String.data is not valid). Is it an URLLoader? in that case, change it to file:URLLoader, or whatever it is (Object maybe?). Also, I don't see the declaration of the "i" variable, is it a class member?

Cay
Ah, my mistake. I will edit the sample code. That's my problem... how do people get around this when working with JSON I wonder, casting as XMLnode? perhaps I should ignore the warnings
cb
+1  A: 

that's not a warning, that's a real error ... String does not have a property data, as Cay mentioned ... I wonder how you ever made this compile with FD in the first place ... did you compile with CS3 or with Flex SDK?

it should be something like

var data:XML = XML(file);
var id:int = data.item.id;/*if your xml looks something like 
          <%ROOT%>
                <item>
                    <id>%SOMEINT%</id>
                </item>
         </%ROOT%>*/

by the way, with JSON, using as3corelib, it'd be

var data:XML = JSON.decode(file);
var id:int = data.item.id;/*if your JSON looks something like
         { item : { id: %SOMEINT% } }

JSON and XML have extremely different semantics, and XMLNode, that you mentioned is ActionScript 2 Legacy, that you shouldnt use ... no offense, but I think you should look at either a JSON or XML/E4X tutorial, since you code and what you say, somehow leads me to believe, you didn't understand some fundamental things, such as the general process:

source string ---parsing/unmarshalling---> intermediary object tree ---traversal---> extracted data

neither can you operate on the source string directly, nor are the intermediary object trees freely exchangable, and thus traversal also depends on used data encoding format (you cannot traverse parsed JSON with E4X, but then again JSON is a semantically equivalent representation of ActionScript values)

greetz

back2dos

back2dos
My apologies for the error, I can't have checked it very well!My point in comparing XML and JSON/arrays of objects, etc is casting a parameter/variable that the compiler does not know exists. Since warnings were cropping up in common library files like Tweener I use a lot, I shan't worry too much but want to know if there is another way of casting XML or Objects. In the meantime I will try to change the settings in FDT
cb