Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there such a thing as an MXML interface

This could potentially be a dumb question so apologies in advance if it is. I'm wondering if theres an equivilant of Interfaces in MXML?

Everytime I feel the need to use an interface I always wind up making an actionscript and not an MXML file because I don't know if / how you can.

For example I was going to have a component based on vbox. I have 4 different implementions of the same thing so I decided to use an interface. But instead of making a single MXML interface and implementing it I've created an interface in as3. I've implemented this interface in 4 different classes.

I then have made 4 different vbox containers each with one of the different implementations in the script tag.

Does this sound like a reasonable approach or am I going against the grain here?

EDIT -- adding examples

The interface

package components.content.contents
{
    public interface IContent
    {
        function init():void;
        function doSearch():void
        function setSearchTerm(term:String):void
    }
}

Implementation (1 of 4)

package components.content.contents
{
    public class ClipContent extends AbstractContent implements IContent
    {
        public function ClipContent()
        {
        }

        public function init():void
        {
        }

        public function doSearch():void
        {
        }

        public function setSearchTerm(term:String):void
        {
        }

    }
}

MXML File (1 of 4)

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
        <mx:Script>
            <![CDATA[
                              // ClipContent Container
                import components.content.contents.ClipContent;
                public var content:ClipContent= new ClipContent()

                public function dostuff():void

                {
                  content.init()
                  content.doSearch()

                }
            ]]>
        </mx:Script>

</mx:VBox>
like image 867
dubbeat Avatar asked Dec 03 '22 05:12

dubbeat


2 Answers

You can use interfaces with MXML components this way:

// YourClass.mxml
<mx:HBox implements="IYourInterface">

is an MXML equivalent of

// YourClass.as
class YourClass extends HBox implements IYourInterface

But you still need to create the interface (in this example IYourInterface) in Actionscript.

like image 132
Robert Bak Avatar answered Dec 23 '22 09:12

Robert Bak


MXML can implement an interface, like Robert Bak said, but it cannot define an interface.

like image 38
JD Isaacks Avatar answered Dec 23 '22 08:12

JD Isaacks