Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do I get a handle to a custom component in Flex?
    primarykey
    data
    text
    <p>I have a custom login component in Flex that is a simple form that dispatches a custom LoginEvent when a user click the login button:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?> &lt;mx:Form xmlns:mx="http://www.adobe.com/2006/mxml" defaultButton="{btnLogin}"> &lt;mx:Metadata> [Event(name="login",tpye="events.LoginEvent")] &lt;/mx:Metadata> &lt;mx:Script> import events.LoginEvent; private function _loginEventTrigger():void { var t:LoginEvent = new LoginEvent( LoginEvent.LOGIN, txtUsername.text, txtPassword.text); dispatchEvent(t); } &lt;/mx:Script> &lt;mx:FormItem label="username:"> &lt;mx:TextInput id="txtUsername" color="black" /> &lt;/mx:FormItem> &lt;mx:FormItem label="password:"> &lt;mx:TextInput id="txtPassword" displayAsPassword="true" /> &lt;/mx:FormItem> &lt;mx:FormItem> &lt;mx:Button id="btnLogin" label="login" cornerRadius="0" click="_loginEventTrigger()" /> &lt;/mx:FormItem> &lt;/mx:Form> </code></pre> <p>I then have a main.mxml file that contains the flex application, I add my component to the application without any problem:</p> <pre><code> &lt;custom:login_form id="cLogin" /> </code> </pre> <p>I then try to wire up my event in actionscript:</p> <pre> <code> import events.LoginEvent; cLogin.addEventListener(LoginEvent.LOGIN,_handler); private function _handler(event:LoginEvent):void { mx.controls.Alert.show("logging in..."); } </code> </pre> <p>Everything looks good to me, but when I compile I get an "error of undefined property cLogin...clearly I have my control with the id "cLogin" but I can't seem to get a"handle to it"...what am I doing wrong?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload