Yes, bracket notation will almost always resolve an object reference.
Very powerful.

Regarding mx:Application, perhaps my terminology is incorrect.

I seem recall that the change to tight typing happened in AS3/FP8/Flex2.


And do remember that in a 1x app we coud do:
this["myvar"] = "myvalue"; //dynamically creating the variable 'myvar'
as a member of Application.

In fact, I was so sure of this that I actually cranked up FB 1.5, and
the Flex server (remember that?) and created this example:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml";
initialize="initApp()">
<mx:Script><![CDATA[
        function initApp() {
                this["myvar"] = "myvalue";      //Dynamically create var
on application. NOT LEGAL IN AS 3!
        }
        
        function alertMyVar() {
                alert(this["myvar"]);
        }
]]></mx:Script>
        <mx:Button label="Test" click="alertMyVar()"/>
</mx:Application>

This does work.

Of course this is so ancient, it is really irrelevant.

Tracy

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Gordon Smith
Sent: Wednesday, February 20, 2008 4:25 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] dynamic function Names

You can look up properties and methods by name with o[p] syntax even if
o isn't an instance of a dynamic class.
 
And I'm pretty sure that <mx:Application> wasn't a dynamic class in 1.x.
 
Gordon Smith
Adobe Flex SDK Team


From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Tracy Spratt
Sent: Wednesday, February 20, 2008 12:49 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] dynamic function Names
As long a "this" is a dynamic object.  In 1.x, mx:Application was
dynamic, in 2+ it is not.
Tracy

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of joshua gatcke
Sent: Monday, February 18, 2008 4:51 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] dynamic function Names
Hi all, after much toil, I have learned that I can have dynamic 
function names doing something like this:

var myFunctionName:String = 'foo';
this[myFunctionName]();

This is awesome! Just thought I would share, but you guys probably 
already knew how to do that ;)

- joshua
 

Reply via email to