【转贴】 Flex 预编译处理 与 手机项目、Web项目、Air项目*转换

时间:2023-03-09 06:45:00
【转贴】  Flex 预编译处理 与 手机项目、Web项目、Air项目*转换

原文连接: http://bbs.9ria.com/forum.php?mod=viewthread&tid=263350#lastpost

由于这个论坛不稳定,所以转到这里来,这个帖子蛮有用的。

《 Flex 预编译处理 与 手机项目、Web项目、Air项目*转换》

作者:七夜

QQ:1016519665

一、flex预编译处理

a.       先随便建个项目,不论手机项目、web项目、还是air项目。(这个自己建个吧,我就不多说了)

b.       新建一个包compile, 里面放个xml格式文件,我们就叫 config.xml 好了,名字随便起啊。

config.xml的内容如下:

<?xml version="1.0"encoding="utf-8"?>
<flex-config>
<default-size >
<width>1250</width>
<height>700</height>
</default-size>
<default-frame-rate>24</default-frame-rate>
<default-background-color>0x000000</default-background-color>
<compiler>
<optimize>true</optimize>
<define>
<name>CONFIG::debug</name>
<value>true</value>
</define>
<define>
<name>CONFIG:desktopOrMobile</name><!-- -->
<value>false</value>
</define>
</compiler>
<metadata>
<title>QiyeTest</title>
<description>Qiye.com</description>
<publisher>Qiye</publisher>
<creator>Qiye</creator>
<language>EN</language>
</metadata>
</flex-config>

  

现在我解释一下这个config.xml的作用。

1.<width>1250</width>   指的是默认宽了,<height>700</height>指的是默认高了。到时候你换些值,清理一下项目,再debug看看就知道了。

2.<default-frame-rate>24</default-frame-rate>指的是默认多少帧。我填了24,你也可以改成其它的,看需求了。

3.<default-background-color>0x000000</default-background-color>指的是默认背景底色为黑色。你也可以改成你想要的颜色。

4.下面关键的来了:

<define>

<name>CONFIG::debug</name>

<value>true</value>

</define>

这个是你自己可以设定的,相当于开关吧。一定要是这种结构的,true就是开的意思,false是关的意思了。

我们就可以在  xxx .as 文件里面使用了.

private function  init():void
{
CONFIG::debug{
Tool.isDebug = true;//设置一些属性
doSomething();//也可以做一些函数处理
}
}

  

<value>true</value>   当这个值为true的时候,CONFIG::debug{ }里面的内容就会执行,为false的时候就不执行。

要想编译器去编译这个文件,你还得做一件事情。

1.  右击你的项目,点击属性

2.  点击  ActionScript编译器

3.  在附加的编译器参数(I): 下面的框内写入一句代码:

-locale en_US -load-config+=compile/config.xml    然后点击确定。

这句话的意思就是告诉编辑器编译项目  按照你 compile文件夹下的config.xml配置内容编译你这个项目。

讲了这么多,也许你会说,这个有个屁用啊。

好,下面我讲下哪些情况下需要用到。

1.  我们都知道trace()不能多,代码里面很多trace说不定就会很消耗,但我们又想做项目的时候debug用它,发布出去正式版的时候不执行这些trace。

那我们就用到上面的方法了,我们自己写个类似trace的类。

package com.qiye
{
public class Tool
{
public static var isDebug:Boolean = false;
public function Tool()
{ } public static functionTrace(value:Object):void
{
if(isDebug) trace(value);
}
}
}

  然后:

CONFIG::debug{
Tool.isDebug = true;
}

  我们只要修改 config.xml  里面

<define>

<name>CONFIG::debug</name>

<value>true</value>

</define>

true 或是false 就好了。当然这个例子举得不太好。

我只是为了阐述一下怎么使用。

2.      多平台的时候:

<define>
<name>CONFIG:esktopOrMobile</name><!-- -->
<value>false</value>
</define>

  

比如说手机上运行、web运行、air运行的一些开关。ANE 的开关。

3. 平台接口,比如说37wan 、各种wan的不同接口,你也可以设置一些开关。

4.   更多,你自己想吧。。我只提了一些。。。至于怎么用就看你了

<metadata>
<title>QiyeTest</title>
<description>Qiye.com</description>
<publisher>Qiye</publisher>
<creator>Qiye</creator>
<language>EN</language>
</metadata>

  这些我就不想说什么了,除非你e文比我还烂。

总结:

1.  新建一个包compile, 里面放个xml格式文件,我们就叫 config.xml 按照我给的格式写,照葫芦画瓢好了。

2.  右击你的项目,点击属性,点击  ActionScript编译器  ,在附加的编译器参数(I): 下面的框内写入一句代码      -locale en_US -load-config+=compile/config.xml    然后点击确定。

3.  需要注意的时候,每次修改完  config.xml  参数的时候,最好清理一下项目,重新编译一下。

4.   你也可以设置多个config.xml的文件,比如叫config_ios.xml 、config_andriod.xml  、config_web.xml  等等,只要把 编译参数 ,第二步 里面的

-locale en_US-load-config+=compile/config.xml   改成

-locale en_US-load-config+=compile/config_xxxx.xml  就好了。

二、Air项目、Web项目、手机项目 *切换

1.一套源码实现Air项目、Web项目、手机项目 *切换

只要把对应的Air项目、Web项目、手机项目下的.actionScriptProperties   .projec  替换到  这套源码 就可以了。

2. 注意 如果是手机项目 、或是 air项目的转换  要修改  项目里面的xxx-app.xml ,换到对应的环境xxx-app.xml   。   xxx 是默认启动应用  .as文件的名字。

例子:比如你的一个项目叫aaa,默认启动应用  aaa.as  ,  那对应的应该就是aaa-app.xml

也许你还不大理解,但你试着去做,就会知道,其实很简单,很方面,记住我说的注意点。遇到问题了,再回来看一遍。

好了,说了这么多,我也累了。大家试试吧~