tags:

views:

75

answers:

1

Is it possible to create an instance of the main MXML and use it inside the ActionScript class.

public  var obj:classname= new classname();

When i try to call a components id through obj.textfieldID... it does not...

though obj is an instance of the classname.mxml.

+1  A: 

I'm not sure but it's possible that control instances are generated as protected. Try adding a public property/method that wraps access to your textfield. You should then be able to access that public member from outside the MXML file.

FYI, though, it's better practice to use binding to populate MXML components. You can add a binding via code using BindingUtils.bindProperty. Even then, though, you would bind a property on the MXML file (either in an <mx:Script> or in 'code-behind' via inheritance) and then have your textField bind to the property:

private var _displayText : String;

[Bindable] // only required on get
public function set displayText(value : String) : void
{
    return _displayText;
}


public function set displayText(value : String) : void
{
    _displayText = value;
}

Then your field would be declared:

<mx:Label id="displayNameLabel" text="{displayName}" />

Now displayNameLabel.text will automatically change everytime you change your (public) displayName property.

Richard Szalay
http://stackoverflow.com/questions/1190444/calling-mxml-inside-actionscript-classCan you help me on this example....