Reputation: 1239
i thought of drawing the interface using mxml markup. When the user clicks on a button it should call a specific method in a .as file. How can i do that in mxml ?
Upvotes: 1
Views: 1623
Reputation: 2122
var class1:AcClass = new AcClass();
then
class1.NameOfMethod();
first instantiate action script class then call its method as above. hope it helps.
Upvotes: 1
Reputation: 12407
Why not create a .as class, and in your mxml file (inside the Script tag) create an instance of the .as class. Then use instanceName.functionName() to call the function. Thats the basic OOP method of doing it. Or use the code-behind pattern
Upvotes: 0
Reputation: 95629
You might find this article helpful. Basically, you use the <mx:Script>
tag to include a script, and then you can set an ActionScript function as the function to execute in response to the button press.
From another article on Adobe's website there is a very simple example:
<?xml version="1.0"?>
<!-- usingas/ASScriptBlock.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script><![CDATA[
public function calculate():void {
var n:Number = Number(fahrenheit.text);
var t:Number = Math.round((n-32)/1.8*10)/10;
celsius.text=String(t);
}
]]></mx:Script>
<mx:Panel title="My Application" paddingTop="10" paddingBottom="10"
paddingLeft="10" paddingRight="10">
<mx:HBox>
<mx:Label text="Temperature in Fahrenheit:"/>
<mx:TextInput id="fahrenheit" width="120"/>
<mx:Button label="Convert" click="calculate();" />
<mx:Label text="Temperature in Celsius:"/>
<mx:Label id="celsius" width="120" fontSize="24"/>
</mx:HBox>
</mx:Panel>
</mx:Application>
Upvotes: 0