开发者

Basic Flex Issue

This is a basic Flex question I have regarding dot syntax. I'm using Flash Builder 4 and whenever I use dot syntax for an object or a URLVariable, F开发者_如何学编程lash Builder is giving me the following warning: The variable action is undefined in dynamic type flash.net.URLVariables

For example:

var vars:URLVariables = new URLVariables();
vars.action = "load leagues";

This also happens with Objects (for example):

var obj:Object = new Object();
obj.view = 55;

However, Flash Builder likes it when I change the syntax to:

vars["action"] = "load leagues";

or

obj["view"] = 55;

The program works with both syntax, but I'm unsure why Flash Builder keeps warning about it. Thanks.


By using the dot syntax this way:
vars.action = "load leagues";

You are telling Flex to assign the value of "load leagues" to the already existing property "action" on the object "vars".

When you assign the value this way:
vars["action"] = "load leagues";

You are telling Flex to assign the value of "load leagues" to the property "action" on the object "vars". If, however, the property "action" does not already exist, create it and then assign the value to it. If the property "action" already exists, then it is telling Flex to simply reassign its value to "load leagues".

Your Flex SDK is probably just warning you that the property has not been properly created on the object, but that it will do it for you. I know it is confusing, but it is important to try and code things as bullet-proof as you can, so it is always better to either explicitly add the property, or to use the [] method to create it on-the-fly if it is not already present.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜