linux下的AS3开发配置

来源:互联网 发布:淘宝色差 编辑:程序博客网 时间:2024/06/05 14:06

同样的文章,三个月以前曾发表在一个AS论坛中,这里重新发表,并做了一些改动。
linux下的程序开发不推荐使用各类集成开发环境,否则也失去了linux平台的意义了。
总的来说,linux下开发AS3,和其他开发语言类似,不外乎选择编辑器,建立类和函数的查找和跳转索引tags,建立自己的帮助文档,建立编译时参数,建立整个工程的编译索引列表xxx-manifest.xml,最后是工程的调试等等。

首先重申,这里没有IDE,因为一直linuxer坚信IDE是各类开发工具的低性能集合,不符合钻研和深究的特性。
然后,至少在当前,linux下开发flash项目还是比较吃力的,因为linux更适合数据和后台的开发,而Flash CS的最新版本一直无法良好运行在linux下,不知将来是否会有所改善。
接着进入正题:

1、编辑器
推荐的编辑器:vim,emacs[e'ma:ks]
vim是vi的扩展版,功能强大,学起来也不会过于困难,命令模式和编辑模式较为符合程序员的习惯和风格。
emacs,说起来emacs已经不属于一款纯粹的文本编辑器了,它甚至可以当成一个小型的shell去编写和处理一些额外的系统指令,功能异常强大,只是语法较为难记,另外,还需额外学习lisp语言。


2、类和函数的查找及跳转索引tags
建立了这个tags以后,可以于编辑器中方便的在不同类和函数之间跳转。
拿vim做例子,打开以后,输入:help,阅读帮助文档。
首先下载exuberant-ctags包,可在Synaptic Package Manager中下载,也可自行apt-get下载。(本文默认你对linux较为熟悉,不是一位新手)

接着通过shell进入工程所在目录,输入ctags -R命令,结束以后当前目录下多了一个tags文件,打开看一下,它就是我们当前工程下所有类和函数及属性的索引表了。
这个时候,一般情况下,ctags默认会忽视.as为后缀的文件,因为它当时开发的时候,并没有将as文件作为处理类型。没有关系,我们可以建立自己的.ctags配置文件。
在用户根目录下,如/home/bolice目录下,建立文件.ctags,输入以下正则表示式:

  --langdef=actionscript
  --langmap=actionscript:.as
 --regex-actionscript=/^[ /t]*[(private| public|protected|static) (/t)]*interface[ /t]+([A-Za-z0-9_]+)[ /t]*//1/i,interface, interfaces/
 --regex-actionscript=/^[ /t]*[(override|private|public|protected|static) ( /t)]*class[ /t]+([A-Za-z0-9_]+)[/t]*//1/c,class, classes/
  --regex-actionscript=/^[/t]*[(override|private| public|protected|static) ( /t)]*function[/t]+([A-Za-z0-9_]+)[ /t]*/(//1/f, function, functions/
 --regex-actionscript=/^[/t]*[(override|public|private|prototype|static)( /t)]*function[/t]+(set|get) [ /t]+([A-Za-z0-9_]+)[ /t]*/(//1 /2/p,property,properties/
  --regex-actionscript=/^[ /t]*[(private|public|protected|static|const) ( /t)]*var[ /t]+([A-Za-z0-9_]+)[/t]*//1/v,varia ble, vari ables/
  --regex-actionscript=/^[/t]*[(private| public|protected|static) ( /t)]*const[/t]+([A-Za-z0-9_]+)[ /t]*//1/v,variable, variables/
  --regex-actionscript=/.*/.prototype /.([A-Za-z0-9 ]+)=([ /t]?)function( [ /t]?)*/(//1/ f,function, functions/

之后,重新生成tags文件。
再打开tags文件看看,是不是不一样了?
注:windows平台下面的ctags属性文件名为:ctags.cnf(即使用ctags.cnf文件名替代.ctags文件名)。
详情参见网址http://gd.tuwien.ac.at/linuxcommand.org/man_pages/ctags1.html。


3、tags文件的使用
还是以vim编辑器为例(以下均以vim为默认编辑器,对emacs的使用者来说,配置可能会略有不同,但大致方向都是相同的)
首先建立当前用户的vim配置。以下是一些常用的vim配置:
 colo evening
 syntax enable
 filetype plugin indent on
 
 set helpheight=300
 set tags=~/Client/ClientDebug/workspace/tags                         "这里很重要,这里是tags的路径,不要设置错误
 set fileencodings=ucs-bom,utf-8,gb18030,cp936,big5,latin1
 
 set number    
 set nobackup   
 set noswf     
 set autochdir 
 set showcmd 

 set hlsearch   
 set incsearch
 
 set autoindent
 set cindent

 let tlist_actionscript_settings = 'actionscript;i:interface;c:class;f:method;p:property;v:variable'  
 autocmd BufRead *.as set filetype=actionscript


"----------------------------分割线以下的内容,做为vim其他配置的扩展乐趣参考,不属于此次配置的基本内容------------------------------------------"
 
 " winmanager
 let g:winManagerWindowLayout = "FileExplorer"
 let g:winManagerWidth=40
 map wm :WMToggle<cr>
 nmap <F10> :wa<cr>:TlistUpdate<cr>:FirstExplorerWindow<cr><F5><c-w>b
 
 "vnoremap _g y:exe "grep /" . escape(@", '///') . "/ *.c *.h"<CR>
 "
 "mapping
 map /p i(<Esc>ea)<Esc>
 map /c i{<Esc>ea}<Esc>
     
 "vim的配置所需插件,均在www.vim.org上下载


4、重要命令的简介。
tag命令
打开vim,比如我们在工程workspace下面有一个类,名字为MyFrame。

在vim中输入
  :tag MyFrame
vim的当前页面便会跳转到MyFrame这个类下面,如果失败的话,请检查类是否定义正确,tags文件是否生成正确,vim配置是否正确指向tags文件。

若我们要搜索一个方法findMe(),但是我们的工程中有很多fineMe()函数的定义,此时,我们可以输入
:tselect findMe
会出现一个列表,指明当前findMe函数的所在类和位置,填入对应的序号,回车即可跳转。

使用vimgrep命令全局
vimgrep命令我们在工程中搜索需要的字符串,比如,我们在当前的工程下要查找单词 "找我啊",可以这样输入:
:vimgrep /找我啊/j   ~/workspace/**/*.as
/后面的j表示找到了也不要跳转。这里支持正则表达式。

之后输入
:cw
打开查找结束的索引框。

使用
:cclose
关闭索引框。

Ctrl+ww(两次w)
可以在索引框和编辑框之间跳转。

其他一些命令,可以在将来的开发中根据自己的喜好自行配置。


5、命令行调试
首先学习flex帮助文档,如果安装了Flex Buidler,可以通过以下方式打开帮助(或F1)。
Adobe Flex 3 Help ->Application Development->using the Flex Compilers

若没有安装Flex 3,需要在网上搜索Flex的Application Development的帮助文档。
下面讲一种解决方案。

5.1、首先找到sdks所在目录,安装了flex以后,此路径一般在{flex-plugin}/sdks/3.0.0中,找到bin目录,并将这个目录加入系统全局变量$PATH,然后在shell中输入mxmlc(即mxml compiler缩写),出现一串命令提示,则安装成功。

5.2、在shell中,进入工程所在目录,输入
mxmlc -dump-load xxx-config.xml
当前目录会出现一个xxx-config.xml文件,这个文件,就是编译时所需的索引配置文件。
生成好了以后,打开看一下吧。

5.3、配置xxx-config.xml配置文件,这个文件,是每个需要编译的子工程的全局配置文件,例如:配置一个工程myTest,我们给-config.xml起个名字myTest-config.xml。接下来进行配置:
   <flex-config>
           <compiler>
 
                   <source-path>
                           <path-element>src</path-element>
                   </source-path>
                   <namespaces>
                           <namespace>
                                   <uri>http://myTest</uri>
                                 <manifest>src/myTest-manifest.xml</manifest>
                         </namespace>
                 </namespaces>

                 <debug>false</debug>
         </compiler>

         <include-namespaces>
                 <uri>http://myTest</uri>
         </include-namespaces>

         <output>bin/myTest.swc</output>
 </flex-config>

<path-element>src</path-element> 表示我们的src源文件相对于当前配置所在位置。

         <include-namespaces>
                 <uri>http://aswing</uri>
         </include-namespaces>
表示我们给当前工程起个自己定义的uri命名空间。以http://开头。这里我们叫 http://myTest

                  <namespaces>
                          <namespace>
                                  <uri>http://myTest</uri>
                                 <manifest>src/myTest-manifest.xml</manifest>
                         </namespace>
                 </namespaces>
这里表示我们在编译的时候,通过上面的 uri,找到了这里的uri,并读取其mannifest文件 src/myTest-manifest.xml, myTest-manifest.xml文件放在当前配置文件目录的src目录下。
这个mannifest文件,是最重要的文件,它相当于一个编译索引表,也取代了ide编译器综合链接所有类文件的功能。
我们看一小段mannifest文件的内容。
<?xml version="1.0"?>
<componentPackage>
        <component id="org.myTest.GeneralListCellFactory" class="org.myTest.GeneralListCellFactory"/>
        <component id="org.myTest.JTextArea" class="org.myTest.JTextArea"/>
        <component id="org.myTest.table.SelectablePoorTextCell" class="org.myTest.table.SelectablePoorTextCell"/>
        <component id="org.myTest.table.TableCellFactory" class="org.myTest.table.TableCellFactory"/>
……
……
……
        <component id="org.myTest.colorchooser.NoColorIcon" class="org.myTest.colorchooser.NoColorIcon"/>
        <component id="org.myTest.colorchooser.VerticalLayout" class="org.myTest.colorchooser.VerticalLayout"/>
</componentPackage>



关于此配置文件的详细说明在帮助文档里有详细的描述。

以下通过一段java代码生成该工程的mannifest文件。

    package xmlFile;
  
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
  
    public class Manifest_xml {
            private  FileWriter fw;
            private static int srcPathLen = 0;
 
           public Manifest_xml(){
 
           }
         
           /**
            * 创建manifest.xml文件
            * @param srcPath: "/home/bolice/workspace/myTest/src/"
            * @param xmlName: "/home/bolice/workspace/myTest/src/manifest.xml"
            */
           public void createXML(String srcPath, String xmlName){
                   srcPathLen = srcPath.length();
                 
                   try{              
                           File file = new File(xmlName);
                           if(file.exists())
                           {
                                   file.delete();
                           }
                         
                           fw = new FileWriter(xmlName, true);
                           fw.write("<?xml version=/"1.0/"?>/n");
                           fw.write("<componentPackage>");                      
                         
                           listFolder(srcPath);        //遍历,需源目录
                         
                           fw.write("/n</componentPackage>");
                           fw.flush();
                         
                           System.out.println("create /"" + xmlName + "/" succeeded");
                   }catch(IOException e){
                           e.printStackTrace();
                   }              
           }
 
           //目录遍历
           private void listFolder(String fileName){
                   File dir = new File(fileName);
                   File[] files = dir.listFiles();
                 
                   if (files == null)
                           return;
 
                   for (int i = 0; i < files.length; i++) {
                       if (files[i].isDirectory()) {
                               listFolder(files[i].getAbsolutePath());
                       }
                       else if(files[i].getName().matches("^[a-z0-9A-Z//_]+//.as$"))
                       {       
                               try{
                                      String strTemp = files[i].getAbsolutePath().substring(srcPathLen,files[i].getAbsolutePath().length()-3);
                                       strTemp = strTemp.replace("/", ".");
                                       fw.write("/n/t<component id=/"" + strTemp +
                                                        "/" class=/"" + strTemp + "/"/>");
                               }catch(IOException e){
                                       e.printStackTrace();
                               }
                       }
                   }
           }
   }


下面是main函数

   import xmlFile.Manifest_xml;;
 
   public class Main {
           /**
            * 创建manifest.xml文件
            * @param1: 所需创建的xml文件绝对或相对路径名
            * @param2: 需遍历的源文件src目录
            * 功能说明:将src目录下所有.as文件的类名取出,放入manifest.xml文件
            * 函数完成则输出:'create "manifest.xml" succeeded'
            */
           public static void main(String[] args) {
                   //创建MyTest-manifest.xml文件
                   (new Manifest_xml()).createXML("/home/bolice/workspace/myTest/src/",
                                   "/home/bolice/workspace/myTest/src/myTest-manifest.xml");
 
           }
   }


6、编译
这里介绍两种编译方式。
compc(即component compiler),编译出的文件后缀名是.swc
mxmlc(上面介绍过),编译出的文件后缀名是.swf
我们编译myTest为myTest.swc,在shell下,转到myTest目录:
compc -load-config+=myTest-config.xml
编译完了以后,则可以找到myTest.swc文件。

接着,编译我们的工程。
首先建立mySwf-config.xml。
<flex-config>
   <compiler>
      <debug>true</debug>

      <include-libraries>
         <library>../myTest/bin/myTest.swc</library>
        <library>/home/bolice/ProgramFiles/Adobe_Flex_Builder_Linux/sdks/3.0.0/frameworks/libs/player/playerglobal.swc</library>
         <library>/home/bolice/ProgramFiles/Adobe_Flex_Builder_Linux/sdks/3.0.0/frameworks/libs/flex.swc</library>

      </include-libraries>

   </compiler>    
   <output>bin/mySwf.swf</output>
</flex-config>


接着,输入:
mxmlc -load-config+=mySwf-config.xml src/mySwf.as
接着,系统会自行编译,报错,或者编译出结果。

7、debug
debug很简单,在shell中输入
fdb
进入debug模式,
输入
run http://localhost/mySwf.swf

调试我们刚才的工程,前提是web服务器已经打开并且http://localhost/world.swf指向刚刚生成的.swf文件。
假如出现Set additional breakpoints as desired, and then type 'continue',表示有断点。
输入continue,便可以继续。

另外利用fcsh可以极大加快编译速度,但是fcsh使用缓存机制,由此可见带来性能的同时,会损失一些其他地方的性能。