开发者

index syntax ('content['xxx']") for accessing members of .SWF

I was actually looking for the adobe docs online that would cover syntax like the following:

SWFLoader(event.target).content['wrFont']

That's from my own code, so obivously I know it works, its just that after 2 years of Flex programming, I have still not encountered any sort of formal documentation on the rules governing this access method (i.e. like in the above wher开发者_开发技巧e I'm accessing the wrFont member of the loaded SWF via an array index syntax and a string.

Specifically, it would be things like, determining if the referenced member even exists - what would be the standard method for doing that (Surely not just a try-catch block right?). But not just that, but formal Adobe Documentation on all relevant aspects of the above. I've downloaded all zipped adobe docs off of their live docs site - where is all this fully documented.

ON a side note, something that's always bugged me about google, is that with a search string like ".content[" it just ignores the "[" character as irrelevant, though if I could just find that search string I would have my answer. But google doesnt search for characters like "[" evidently. Neither does Bing. Does any search engine do this.


The [ and ] - "array" access - can be used on ANY object, or a derivate of one (that is everything except numbers, strings, booleans).

To properly see if a child exists, use the .hasOwnProperty method.


If you want to make sure your a given member exists you code test like this :

if(SWFLoader(event.target).content['wrFont']) = null)

But this is not really recommended because your actually don't if the type of the content you are loading actually has this property or not.

What you should do in your case in cast the "content" property of SWFLoader to its actual class, or even better, use an interface to decouple your SWF files :

public interface IWRFontContainer {
   function get wrFont():Font;
}

Make your SWF main/document class implement this interface and then cast the content where you are loading it:

var swf:IWRFontContainer = SWFLoader(event.target).content as IWRFontContainer;
trace(swf.wrFont);

To make sure your content is of type IWRFont, you can check the type using the isto check the type or use a try/catch block.


The Object ASDoc has some explanation: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Object.html

"All classes that don't declare an explicit base class extend the built-in Object class.

You can use the Object class to create associative arrays. At its core, an associative array is an instance of the Object class, and each key-value pair is represented by a property and its value. Another reason to declare an associative array using the Object data type is that you can then use an object literal to populate your associative array (but only at the time you declare it). The following example creates an associative array using an object literal, accesses items using both the dot operator and the array access operator, and then adds a new key-value pair by creating a new property:..."

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜