有没有这样一个MXML接口的东西 [英] is there such a thing as an MXML interface

查看:248
本文介绍了有没有这样一个MXML接口的东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果是的话,这可能是一个愚蠢的问题,所以提前道歉。
我想知道是否在MXML接口equivilant吗?

每当我觉得有必要使用一个接口,我总​​是结束了一个动作,而不是一个MXML文件,因为我不知道是否/如何可以。

例如,我将有一个基于vbox的组件。我有4个不同的实现相同的东西,所以我决定使用一个接口。但是,而不是做一个单一的MXML接口和实现它,我已经在as3中创建了一个接口。我已经在4个不同的类中实现了这个接口。

然后,我制作了4个不同的vbox容器,每个容器都带有脚本标记中的不同实现。



这听起来像一个合理的方法,或者我在这里反对谷物?



编辑 - 添加示例



界面

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

执行(1 of 4)

 包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
{
}

}
}
pre
$ b $ MXML文件(1 of 4)

 <?xml version =1.0encoding =utf-8?> 
< 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>


解决方案

/ p>

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

是相当于MXML的

<$ p $ $ YourClass extends HBox implements IYourInterface



// YourClass.as
<但是您仍然需要在Actionscript中创建接口(在本例中为IYourInterface)。

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>

解决方案

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.

这篇关于有没有这样一个MXML接口的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆