在Flex 4.6中使用外部包含文件

时间:2014-06-20 19:16:13

标签: actionscript-3 flex progress-4gl openedge flex4.6

如何在代码中包含编译时包含的MXML中插入代码片段,例如Progress includes?例如:in Progress我用这种方式做我想做的事。

MyInclude.i

DEF VAR myVar AS CHAR NO-UNDO.  
FUNCTION fnSetChar RETURNS LOGICAL:  
ASSIGN myVar = 'test'.  
END FUNCTION.

MyProgram.p

{MyInclude.i}
MESSAGE fnSetChar() SKIP myVar
VIEW-AS ALERT-BOX BUTTONS OK.

有许多方法可以使用include in progress,传递参数,重用代码等。

我想知道是否有人知道如何在Flex中执行此类操作。即:

<fx:Declarations>
//include the content of the "include file" here in compile time
</fx:Declarations>

抱歉我的英文。希望有人能帮助我。

感谢。

1 个答案:

答案 0 :(得分:0)

基于How would I include an MXML file inline another MXML file?,无法完全 你所要求的。但是,您可以使用Actionscript而不是MXML轻松地重写<s:HTTPService>个对象。

所以你会在MyFlex.mxml中找到它:

<s:Application ...>
  <fx:Declarations>
    <s:HTTPService id="service1" url="http://www.example.com/s1/" />
    <s:HTTPService id="service2" url="http://www.example.com/s2/" />
    <s:HTTPService id="service3" url="http://www.example.com/s3/" />
  </fx:Declarations>

  <s:Group id="visualContainer">
    <!-- other visible controls here -->
    <s:Button label="Service one" click="service1.send()" />
  </s:Group>
</s:Application>

以下内容:

<s:Application ...>
  <fx:Script source="includes/IncludedFile.as"/>

  <s:Group id="visualContainer">
    <!-- visible controls here -->
    <s:Button label="Service one" click="service1.send()" />
  </s:Group>
</s:Application>

包括/ IncludedFile.as:

var service1:HTTPService = new HTTPService("http://www.example.com/s1/");
var service2:HTTPService = new HTTPService("http://www.example.com/s1/");
var service3:HTTPService = new HTTPService("http://www.example.com/s1/");

有关此主题的更多信息,另请参阅Including versus importing ActionScript code