The application object has references to those objects that are declared
with ids in the <Application> file. However, it doesn't have references to
objects declared with ids inside MXML components. These references are on
the object declared at the top of the MXML component file. For example, if
you write AddressForm.mxml as

    <mx:Form>
        <mx:TextInput id="firstName"/>
        ...
    </mx:Form>

then the corresponding ActionScript class is

    class AddressForm extends Form
    {
        var firstName:TextInput;
        ...
    }

so the firstName reference is on the Form object, not the Application
object. So from an <mx:Script> in AddressForm.as, you would use this[id],
not Application.application[id], if you had to get the firstName reference
given the string id="firstName".

- Gordon


-----Original Message-----
From: Manish Jethani [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 21, 2005 1:29 AM
To: [email protected]
Subject: Re: [flexcoders] string object id to object



On Mon, 21 Mar 2005 01:33:55 +0100, Krzysztof Szlapinski <[EMAIL PROTECTED]>
wrote:

> Let's say I've got a string variable that holds the id of an object in my
> application:
[snip]

> How can access this object with only this string id?

The application object holds references to these objects using their
ids.  Think of the application object like this:

  class MyApplication extends Application {
    var vbox:VBox; // refers to <mx:VBox id="vbox">
  }

So you can get to the vbox by looking it up in the application object:

  import mx.core.Application;

  var vboxId:String = "vbox";
  trace(Application.application[vboxId].height);  // height of
<mx:VBox id="vbox">

You can do this from anywhere in the your application.  You have to be
careful when you have nested applications though --
Application.application refers to the _top-level_ application.  See
also: UIObject.parentApplication.

Manish


 
Yahoo! Groups Links



 





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to