문제

I am having a very weird behavior in my program, and after trying many things and searching here for a possible answer but without success, I decided I'll ask here as a new question. So here is my problem:

I'm using describeType() so got an E4X XML object describing my class. My class has a metadata [Table] with no argument:

[Table]
class MyClass extends ORM
{
    [...]

The XML object when debugging is correct:

trace(xmlDescription.metadata.@name[0]);
// output "Table"
trace(xmlDescription.metadata.(@name == "Table").length());
// output... 0!!!!

Also checking the XML object I got the correct structure with the wanted node:

<metadata name="Table"/>

While doing my research I remembered about the XML.ignoreWhitespace attribute. I tried to set it to false before calling describeType() but nothing changed

So any idea how I can get this metadata node in a XML type variable which I should logically get using (but I'm getting null as result):

xmlDescription.metadata.(@name == "Table")[0]

???

Thanks in advance

PS: I'm using Flash Builder 4.6

도움이 되었습니까?

해결책

Wow, after sharing the question on Facebook not hoping any answer from there at all, I got one working from an old coworker:

Apparently there is a bug which appeared in Flash Builder 4, and my problem is in its scope. To "fix" it, you have to use a local variable of type String to be able to make it work. So replacing my code like below make it work:

// before:
public function uniqueMetadata( metadataName : String ) : ReflectionMetadata
{
    var x : XML = xmlDescription.metadata.(@name == metadataName)[0];
    // x is null here

// after
public function uniqueMetadata( metadataName : String ) : ReflectionMetadata
{
    var s : String = metadataName,
        x : XML = xmlDescription.metadata.(@name == s)[0];
    // x is not null and contain the desired node!

So yes, weird weird workaround. I seriously don't understand how such a bug can happen...

Anyway, now it's working and I'm looking for other places like that in my code where I need to copy the value of an argument in a local variable of the same type before doing some E4X filtering lol

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top