In ActionScript, how can you test if an object is defined, that is, not null?
相关问题
- garbage collection best practices
- How to load flex swf from flash?
- FlashDevelop Haxe (Flash) debugger
- Converting Date with Time in PST into UTC format
- Detecting user's camera settings
相关文章
- Are there any benefits when using final in AS3?
- Trace on Chrome/Browser console
- as3 ByteArray to Hex (binary hex representation)
- Libraries for text animation in Flex / Actionscrip
- About Collision detection alghorithms in AS3
- How to upload BitmapData to a server (ActionScript
- Manage resources to minimize garbage collection ac
- as3 object values NativeText
Just test it against null.
For ActionScript 3.0, if all you want is a generic test for nothingness, then it's very easy:
In the example above, only
c
will trace. This is usually what I need, and just checkingif (obj)
is the most readable version.This method uses implicit conversion to a boolean value, also known as boolean coercion, and the details of what values will coerce to false and what values will coerce to true follow ECMA standards and are also documented specifically for ActionScript.
This works in AS2 and AS3, and is the most reliable way to test if an object has a value.
Its also the most reliable way to test an object's property and read it in the same expression:
There's a difference between null and undefined, but if you don't care you can just do a normal comparison between either one because they compare equal:
is the same as
If you care about the difference, use the === or !== operator, which won't convert them.
You could also loop through a parent object to see if it contains any instances of the object you're looking for.