apache-flexactionscript-3flex-builder-3

Flex compiler warning - variable 'item' has no type declaration


I am tyring to learn flex programming myself. Below code gives me a warning

variable 'item' has no type declaration.

var xml:XML = xml as XML;

for each (var item in xml.employee) {
    Alert.show(item.@name); 
}

What is the type of variable item? I thought it was XMLNode, but it give me error. I want to remove the compile warning.


Solution

  • Use this please, you haven't initialized item.

    
    var xml:XML = new XML();
    
    for each (var item:XML in xml.employee) {
        Alert.show(item.@name); 
    }