
182 Create a Custom Component
6. Enter the following code in the CDATA construct:
private function handleLoginEvent():void {
lblTest.text = "logging in...";
//login logic
}
In a real application, the handleLoginEvent function would reference or contain the
logic for validating and submitting the login entries for authentication. Developing the
logic for the handler is outside the scope of this lesson.
The keyword
private specifies the function’s scope. In this case, the function is available
only within the component. If you set the scope to
public, the function is available
throughout your code.
The keyword
void specifies the function’s return type. All ActionScript functions should
specify a return type. The
handleLoginEvent function returns no value.
The code for the component should look as follows:
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
width="275" height="150" title="Member Login">
<mx:Script>
<![CDATA[
private function handleLoginEvent():void {
lblTest.text = "logging in...";
//login logic
}
]]>
</mx:Script>
<mx:Label x="10" y="12" text="Username"/>
<mx:Label x="10" y="42" text="Password"/>
<mx:TextInput x="74" y="10" id="txtUID"/>
<mx:TextInput x="74" y="40" id="txtPwd" displayAsPassword="true"/>
<mx:Button x="178" y="70" label="Login" click="handleLoginEvent()"/>
<mx:Label x="74" y="72" id="lblTest"/>
</mx:Panel>
7.
Save the file.
Use the custom component
The next step is to add the custom component to your MXML application file, and then to
compile and run the application file to test the component.
1. In Design mode, switch to the Main.mxml file.
Commenti su questo manuale