1
votes

I have a mxml application which is loaded into another movie. this requires it to implement certain functions. is it possible to have the main class of an mxml app to implement an interface? if yes, how?

2

2 Answers

3
votes

Every mxml component (and Application too) has implements property where you can add your interfaces. Here's example:

App.mxml:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               minWidth="955" minHeight="600"
               implements="IInterface">
    <s:layout>
        <s:VerticalLayout />
    </s:layout>
    <fx:Script>
        <![CDATA[

            public function one():void
            {
                // TODO Auto Generated method stub

            }

            public function get prop():String
            {
                // TODO Auto Generated method stub
                return null;
            }

            public function set prop(value:String)
            {
                // TODO Auto Generated method stub
                return null;
            }

        ]]>
    </fx:Script>


</s:Application>

IInterface.as:

package
{
    public interface IInterface
    {
        function one():void;

        function get prop():String;
        function set prop(value:String);
    }
}
0
votes

Please try some thing like this: - Hope below code may help you --

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               implements="pkgCom.IAlpha">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[

            public function updateName():void {
                //code
            }
            public function updateValue():void {
                //code
            }
            public function updateValue1():void {
                //code
            }

        ]]>
    </fx:Script>
</s:Application>

Interface Name: - IAlpha Package Name: - pkgCom

package pkgCom
{
    public interface IAlpha {
        function updateName():void;
        function updateValue():void;
        function updateValue1():void;
    }
}