用程序生成swf(flash)文件: ming 和 swftools

用程序生成swf(flash)文件: ming 和 swftools
ming(http://ming.sourceforge.net/)和swftools(http://www.swftools.org /)都是开源的项目,都是用c编写的.都可以用来生成swf文件,包括在swf文件内增加图片,声音,视频等素材,也可以在文件内增加代码,使用滤镜.
区别是:
ming:使用起来更方便,资料更多(我所看到的),as支持更好,就是更新太慢.
swftools:工具更齐全(有十多种工具,见下文).但是资料不多.

ming(可以使用php,perl,python生成swf文件,php5安装的时候自带,php5帮助里面用完整的函数说明):
sf: http://ming.sourceforge.net/
更新信息:

http://www.libming.net/moin.cgi/%e6%9c%80%e6%96%b0%e6%94%b9%e5%8a%a8

最近版0.4beta4:

http://sourceforge.net/project/showfiles.php?group_id=18365&package_id=187304

最新版本信息:

http://www.libming.net/moin.cgi/Releases

使用ming开发的站点列表:

http://www.libming.net/moin.cgi/Websites_using_Ming

大量的ming的php实例和源码(看了这些代码你就知道生成一个swf是多么简单,但是你最好明白每句代码的含义):

http://www.gazbming.com/

swftools:
最近版本0.8.1:http://www.swftools.org/download.html
文档(内容太少了):http://www.swftools.org/documentation.html
工具和介绍:
* PDF2SWF A PDF to SWF Converter. Generates one frame per page. Enables you to have fully formatted text, including tables, formulas etc. inside your Flash Movie. It’s based on the xpdf PDF parser from Derek B. Noonburg.
* SWFCombine A tool for inserting SWFs into Wrapper SWFs. (Templates) E.g. for including the pdf2swf SWFs in some sort of Browsing-SWF.
* SWFStrings Scans SWFs for text data.
* SWFDump Prints out various informations about SWFs.
* JPEG2SWF Takes one or more JPEG pictures and generates a SWF slideshow.
* PNG2SWF Like JPEG2SWF, only for PNGs.
* GIF2SWF Converts GIFs to SWF. Also able to handle animated gifs.
* WAV2SWF Converts WAV audio files to SWFs, using the L.A.M.E. MP3 encoder library.
* AVI2SWF Converts AVI animation files to SWF. It supports Flash MX H.263 compression. Some examples can be found at examples.html.
* Font2SWF Converts font files (TTF, Type1) to SWF.
* SWFBBox Allows to readjust SWF bounding boxes.
* SWFC A tool for creating SWF files from simple script files.
* SWFExtract Allows to extract Movieclips, Sounds, Images etc. from SWF files.
* RFXSWF Library A fully featured library which can be used for standalone SWF generation. Includes support for Bitmaps, Buttons, Shapes, Text, Fonts, Sound etc. It also has support for ActionScript using the Ming ActionCompiler.

在PHP/JSP中用MTASC编译AS在线生成SWF的方法与介绍

这个方法说老实话我不喜欢,因为要用SHELL.
MTASC是一种用将.as源文件编译成.swf文件的命令行编译器.
在PHP允许SHELL的情况下可以调用。

http://hossy.net/sssc/

这就是作者的地址。
其实没什么难度,因为工作都是MTASC完成的。不能让PHP独立完成。
除了PHP搭建MTASC外壳还有用JAVA搭建MTASC外壳的

http://www.scotthyndman.ca/?p=73

现在有没有不用MTASC做??

网上搜集的一些FLEX面试题

1. 使用Flex Bulider3 建立一下新的.mxml 的页面时默认的背景是蓝色的, 请问用什么办法能修改掉此背景颜色, 以至于下次创建时背景不是为默认的蓝色的呢? 请写出你认为正确的方法。

答:修改sdk\frameworks\projects\framework\default.css 里Application 的backgroundColor: #0000FF;

2. 使用Flex Bulider3 如何跟踪程序?

答:我知道的三种1.trace() 2. 设置断点 3. 当不在调试模式时可以调用as 的Alert.show() 或js 的alert() 如:navigateToURL(new URLRequest(“javascript:alert(traceMsg)”), “_self”);

3. 请问enterFrame 和timerEvent 这2 个事件有什么区别? 请说下具体的使用方法和相关的使用场合?

答:enterFrame 是按帧发生,timeEvent 是根据设置的Timer 类参数发生。如:

用ENTER_FRAME 控制小球圆周运动:

addEventListener(Event.ENTER_FRAME,ballMove);

用TIMER 控制小球圆周运动:

var myTimer:Timer=new Timer(83.3,0);// 关于该数的设置见TIMER 类的说明

myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER,ballMove);

4. 请说下你理解AS3 的事件机制是什么机制? 你认为正确的就可以说出来.

答:建立一个完整的事件机制需要四个步骤:注册侦听、分发事件、侦听事件、移除侦听。建立成功后,触发事件,事件流会进行捕获、目标和冒泡三个阶段。捕获阶段由FP 沿显示列表从根容器往下层层寻找触发事件的目标对象,找到后即进入目标阶段。然后,事件对象从目标对象再次沿显示列表往上移动至根容器,遇到注册侦听的节点就调用侦听函数。如果想中途中断冒泡,可以使用stopPropagation 。

5. 请问addEventListener 里面有几个参数, 你能说出具体的使用方法嘛?

答:addEventListener(

type:String, 事件的类型

listener:Function, 监听函数

useCapture:Boolean = false, 是否打开捕获功能

priority:int = 0, 监听器优先级别

useWeakReference:Boolean = false 是否使用弱引用

)

6. 请问我想判断一个字体是否是数字, 用什么办法去判断呢?

答:isNaN(parseInt(strPara) 或 strPara is Number

7. 请问我想判断一个字符或者一个对象的类型怎么判断呢?

答:typeof(obj)

8. 请问你了解 internal 控制符么? 能说下具体使用方法和场合嘛?

答:internal 是默认的包内访问,体现了封装思想和package 模块化思想。举例来说,A 类需要使用B 类和C 类的方法和属性,但又不希望它们对其他类暴露,只要将A,B,C 放入同一包内,包外的其他类就无法使用B ,C 类了。

9. 我想在某一点不去执行任何内容, 也就是说我想停止执行了, 你知道要怎么做嘛?

答:设置断点

10. 请问 undefined 和 null 是否一样, 如果不一样能否说出其中的区别呢?

答:undefined 是尚未初始化的无类型变量或未初始化的动态对象属性的特殊值。null 是一个可以分配给变量的或由未提供数据的函数返回的特殊值。它们的相同之处在于都未初始化,不同在于undefined 是无类型或动态类型的。如:

var v1;trace(v1);//undefined

var v2:*;trace(v2);//undefined

var v3:Object;trace(v3);//null

11. 创建常量知道怎么创建嘛? 说下你是怎么创建的.

答:const PI:Number = 3.1415926; public static const STARTUP:String = “startup”;

12. 请问用什么方法自定义一个事件呢? 说下具体的方式.

答:(1) 扩展Event 类或其子类

(2) 定义一个static const 常量作为事件的type 传入构造函数

(3) 定义一个私有变量作为事件的Data 保存数据,并为其添加getter 和setter

(4) 覆盖toString() 和clone() 方法

13. 请问怎么样检测本机的内容呢, 比如说, 我想知道本机的操作系统, 是否有视频等这些.

答:flash.system.Capabilities.os 当前的操作系统

flash.system.Capabilities.hasStreamingVideo 系统是否可以播放视频流

14. 请问用什么办法解决安全域的问题? 如果你不知道安全域的问题的话, 可以在本机中绑定一下图片, 然后再放到服务器上, 就会出现此问题了.

答:配置安全沙箱的策略文件crossdomain.xml 放置到服务器根目录,如:

15. 有三种基本数字类型:number, int, 和uint 请问有什么区别. 具体说一下.

答:number 数字类型包含浮点型( 正0 负); int 整型( 正0 负); uint( 无符号整型)

16.parseInt 此方法转化为int 型的方法, 请问你知道此方法的第二个参数是什么意思嘛?

答:指定第一个参数字符串的进制,范围为2-36 。例如parseInt(“100”,2)=4

17.Math.round( ) , Math.floor( ) 和Math.ceil( ) 三个方法都是四舍五入, 请问有什么区别?

答:round 是取最接近的整数,即原数+0.5 后取整;floor 向下取整;ceil 向上取整

18. 请问一个数组里可以放不同的类型嘛?

答:可以,如var x:Array = ['a',1,new Button()];

19.var letters:Array = ["a", "b", "c"]; 我想在这个数组里搜索‘c ’字符, 请问怎么办?

答:for(var i:* in letters)

if(letters[i] == ‘c’) trace(“c’s position is ” + i); 或

if(letters.toString().indexOf(‘c’) > 0)

trace( “c’s position is ” + letters.toString().indexOf(‘c’) );

20. 怎么样转换数组为字符串, 怎么样将字符串转化为数组?

答:数组-> 字符串:trace(new Array(‘a’,'b’,'c’).join(“”).toString());

字符串-> 数组: var arr:Array = new String(“a,b,c”).split(‘,’);

21. 我想创建的视图居中怎么办?

答:布局策略里面限定为居中,即horizontalAlign=”center” verticalAlign=”middle”; 或者在每个控件都以舞台的中心作为相对坐标来计算各自的xy 值。

22. 请问知道层级的概念嘛? 如果知道请问怎么样交换2 个组件的层级呢?

答:层级表示的是显示对象在显示列表中的位置,从第0 层开始,位于最下面。

交换组件层级可以使用id 交换,也可以直接交换层级索引。如:

my_sprite.swapChildren(my_ball2, my_ball1);

my_sprite.swapChildrenAt(2, 1);

23. 请问你知道loader,URLLoader,URLStream 这个三种动态加载资源的具体使用场合, 以及有什么区别嘛?

答:(1)Loader 像2.0 中MovieClip 的loadMovie 功能,用于加载外部的图片和SWF 文件。使用 load() 方法来启动加载。被加载的显示对象将作为 Loader 对象的子级添加。在使用Loader 加载数据,添加侦听事件时,一定要给Loader 的contentLoaderInfo 属性增加事件,而不是给Loader 对象增加事件。

(2)URLLoader 类以文本、二进制数据或URL 编码变量值对的形式先从URL 下载数据,然后才将数据用于ActionScript 。它会发出有关下载进度的通知,通过bytesLoaded 和bytesTotal 属性以及已调度的事件,可以监视下载进度。

(3)URLStream 类提供对下载URL 的低级访问。数据一下载,便可随即为应用程序使用,这和使用URLLoader 需要等到整个文件下载完不同。并且URLStream 类还允许在完成下载前关闭流。已下载文件的内容将作为原始二进制数据提供。

(4)URLStream 、URLLoader 、Loader 等读取外部数据的类,类里的load 方法参数值是URLRequest 对象。如:

var request:URLRequest=new URLRequest(“httpURL 地址”);

loader.load(request);

24. 如何把MouseEvent 的localX 和localY 属性转化成全局坐标?

答:全局坐标系:stageX,stageY 。原点位于舞台左上角。

本地坐标系:localX,localY 。原点位于相对组件的左上角。

内容坐标系:contentMouseX 和contentMouseY 。描述鼠标相对于整个容器内容的位置,用于当子组件的高或宽可能超出容器自身设置高宽的情况。

转换方法:

contentToGlobal 内容到全局坐标

contentToLocal 内容到本地坐标

globalToContent 全局到内容坐标

globalToLocal 全局到本地坐标

localToContent 本地到内容坐标

localToGlobal 本地到全局坐标

25. 请问我现在有一个正方形的图片, 我想把他做成圆形, 有什么办法呢? 前提是用flex 或者as3

答:不清楚,是不是用BitMapData 的draw 方法实现呢?会的朋友请告诉我。

26. 请问新创建的一个sprite 能否被直接加到ui 容器里? 如果不能请说出用什么办法能加入.

答:不能。先将sprite 加入一个扩展自UIComponent 的类,再加入UI 容器。

27. 我怎么设置把一个文本框, 设置成一个密码框?

答:将displayAsPassword 属性设置为true

28. 我想在文本框里只能输入abcd, 有什么办法能做到呢? 如果我想输入除abcd 以外的其它都能输入又怎么做呢?

答:restrict=”a-d” 。restrict=”^(a-d)”

29. 请问condenseWhite 这个属性在TextInput 里是表示什么意思?

答:仅会应用于通过htmlText 属性设置的文本,默认为false 。当设置为true 时,会删除文本中额外的换行和空白。

30. 我现在刚创建的文件的text 为 this is a text, 我想设置光标在 is 上, 请问怎么设置?

答:触发事件,在侦听函数上让selectionBeginIndex=5,selectionEndIndex=6

31. 请问怎么样在文本框里添加超链接?

答:(1) 使用文本框的htmlText 属性添加必须以”event:” 开头的超链接,如 这儿

(2) 添加对TextEvent.LINK 事件类型的侦听,如addEventListener(TextEvent.LINK,clickLink);

(3)”event:” 后面的字符串将被包含在侦听事件的text 属性里,如

private function clickLink(event:TextEvent):void

{

var cmdArray:Array = event.text.split(“|”);

if(cmdArray[0]==”geturl”)

navigateToURL(new URLRequest(cmdArray[1],cmdArray[2]);

}

32. 我想获取系统里的字体, 请问怎么办?

答:import flash.text.Font;

var allFonts:Array = Font.enumerateFonts(true);

allFonts.sortOn(“fontName”, Array.CASEINSENSITIVE);

var fontsLength:int=allFonts.length;

for(var i:int=0;i

trace(" 字体名称:"+allFonts[i].fontName+" 字体样式:"+allFonts[i].fontStyle+" 字体类型:"+allFonts[i].fontType)

33.substring( ) ,substr( ), slice(), 请说下3 种解析字符串的不同之处, 以及适用场合?

答:substring(v1,v2): 截取从v1 到v2 的字符串,包括v1, 不包括v2

substr(v1,v2): 从v1 开始,截取v2 长度

slice(v1,v2): 类似于substring ,不过可以接受负值参数,表示倒数第几位

34. var fruits:XML =

Apple

Orange

Pear

Watermelon

;

以下有一个字符串, 我现在知道了color 为orange, 我想知道此color 相对应的name 节点的值, 我应该怎么做?

答:原题的XML 不规范。找到name 节点值可以用fruits.fruits(@color==’orange’).name

35. 请说下目前使用flex 和后台交互的几种方法, 以及适用场合.

答:(1) 基于AMF 消息格式的RemoteObject 组件,如Lcds/BlazeDs ,AMFPHP 等。

(2) 基于SOAP 消息格式的WebService ,对于使用SOAP 的服务器方便连接。

(3) 基于纯文本或拥有良好格式的XML 消息格式的HTTPService 组件。

一般来说,选用高效稳定的RemoteObject 中间件。

36. 我现在想在flex 里调用JS 方法, 我要怎么办呢?

答:直接在AS 中使用ExternalInterface.call() 来调用JS 方法。如:

import flash.external.ExternalInterface;

ExternalInterface.call("simpleJSFunction");

ExternalInterface.call("simpleJSFunctionWithParameters","myParameter");

var result:String=ExternalInterface.call("simpleJSFunctionWithReturn");

37. 我想用JavaScript 调用ActionScript 函数, 我要怎么办呢?

答:使用ExternalInterface.addCallback 在JavaScript 里设置对Flex 的回调方法并且在JavaScript 里调用ActionScript 方法。

AS:

ExternalInterface.addCallback("function1",callback1);

privatefunctioncallback1():void

{

Alert.show("callback1executed");

}

JS:

container[swf].function1();

38.FileReference 请说下此对象的几个相关事件

答:browse(typeFilter:Array = null):Boolean 显示一个文件浏览对话框,让用户选择要上载的文件。

cancel():void 取消正在对该 FileReference 对象执行的任何上载或下载操作。

download(request:URLRequest, defaultFileName:String = null):void 打开对话框,以允许用户从远程服务器下载文件.

upload(request:URLRequest, uploadDataFieldName:String = "Filedata", testUpload:Boolean = false):void 开始将用户选择的文件上载到远程服务器。

1.as2 与as3 的最主要区别是什么?

答:首先,as2 和as3 是完全不同的语言,几乎没有兼容性可言。as2 编译用的AVM1 虚拟机,as3 用的AVM2 ,速度快,提供了一些基础异常处理。 as3 是纯的OOP ,强类型语言。as2 不是。具体的差别有太多太多。

2.flex 的开发框架有哪些,它们有什么优缺点?

答:最常见的当然是Cairngorm 、Puremvc 了,此外还有Mate ,Swiz 等等,据说被广泛应用的已经有10 几款了。Cairngorm 作为Adobe 官方出品,有着贵族血统的它比较全面,是这些框架中已知bug 最少的,但是基于他的应用相对臃肿复杂一些,需要对每个可以被触发的事件写一个对应的Command ,编码量巨大,并且单元测试很不容易,不适合敏捷开发。Puremvc 应该是现在用的最多的as 框架了。比较完善、并且与Cairngorm 相比,更适合中小型应用的开发,它与Cairngorm 一样,也是以MVC 模式为中心,并以Façade 作为中央存储器的单件类的形式进行开发的。说下Mate ,它是一个比较奇怪的框架,是基于标签的事件驱动型的。也就是说你不能再随意的写as 类的,在使用Mate 的情况下,只能用MXML 来做这些事情。Swiz 是Mate 的孪生兄弟,长的挺像,没具体用过,不大了解。

3. 在flex 开发中,很多代码都写在mxml 文件里,为了做到mvc 模式,你是怎么处理的。

答:我认为mxml 并不影响mvc 模式啊。分两种情况来讨论,首先,是自己创建整个应用结构的时候,那我们可以手动将UI 所在的mxml 归为一类,然后由Mediator 去操作或者说控制这些组件既可了,然后Mediator 又统一交给Controller 去操作。如果采用其他框架来进行开发的话,那就更不用来考虑这个问题了,像Cairngorm 、Puremvc 之类的框架已经很好的为我们解决了这些问题。只要按照它们的使用规范来进行开发,自然没有问题。

4. 如果发生内存泄露,你是如何解决的?

答:在profile 观察中已经内存泄漏是没有很好的解决办法的,至少我不知道,我能做的只是尽量去避免这种情况的发生,比如说注意不要循环引用,特别是在使用Timer 的时候要格外注意,不要忘记全局对象上的引用的清除,在创建控制器和模型的时候要注意一定要使用单件模式。在addEventListener 时候尽量采用弱引用、自引用、或者子对象引用,以避免内存泄漏。

5.as3.0 垃圾回收器是如何工作的?

答:flash player 8 之前采用的是引用计数法,在flash player 8 之后用的是标记法,简单的说就是:从应用的根节点开始,遍历所有其上的引用,标记每个它所发现的对象。然后迭代遍历每个被标记的对象,标记它们的子对象。这个过程递归进行,直到Player 遍历了应用的整个对象树并标记了它所发现的每个东西。在这个过程进行的时候,可以安全地认为,内存中那些没有被打标记的对象没有任何活动引用,因此可以被安全地释放内存。一般来说,flash player 采用的是一种低频的垃圾回收机制,Flash Player 的垃圾回收发生在Flash Player 需要另外请求内存之前。但并不是每次应用申请内存时都会导致垃圾回收的执行,只有当Flash 占用的内存紧张到一定程度时才会执行真正的垃圾回收,一定程度上取决于客户端计算机的物理内存的大小。

6 flex 和后台语言是如何交互的?

答:见第35 题。

7. 你是如何处理前端速度慢的问题?

答:flex 前端速度慢 其实仔细说应该分2 部分,1. 是flex 生成的swf 由于SDK 庞大的关系,swf 体积也跟着庞大了,这我们可以做的就是用Module 动态加载,还有就是RSL 了。2. 处理速度慢,远程方法速度慢,这是AVM 的硬伤了,基本没有很好的解决方法,我们能做的只是让这个异步进行的更完美一些,让用户在等待的过程中,做其他的事情,以至于让用户忽略这段等待的时间。

8.flash 与flex 是如何协调开发的?

答:这个问题可以这样来理解,如果是确实需要用到FLEX SDK 的应用,那我们就可以建立一个flex 工程,具体需要flash 做UI 的时候,输出成swc 作为flex 的skin ,如果说并不需要flex sdk ,只是为了编码方便而选择flex 的话,那我们只要建立一个as 工程,让flex 作为flash 的编码器。

组件

1. 我不想在容器里显示滚动条怎么办?

答:指定horizontalScrollPolicy 和verticalScrollPolicy 为off

2. 请问Flex bulider3 可以创建几种不同的项目?

答:三种。Flex Project 、 AS Project 和Flex Library Project 。

3. 你了解RSL 嘛? 请说明下RSL 的使用方法, 以及使用RSL 为了解决什么问题?

答:RSL(Runtime shared libraries) 即动态链接库,在程序运行时由FlashPlayer 动态加载。静态链接库是SWC 文件,通过编译器的library-path 和include-libraries 编译进应用程序。采用静态链接的应用程序SWF 会产生比较大的文件以及更长的下载时间。使用RSL 的应用程序载入时间短且文件比较小,而且提高了内存使用效率,只是在开始需要花点时间下载RSL 。RSL 的强大体现在多个应用程序共享公共代码时,因为RSL 只需要被下载一次,多个应用程序动态链接到相同的RSL ,访问其中已经缓存在客户端的资源。

使用RSL :

(1). 在项目文件夹中点右建, 选择"properties"-"Flex Build Path"-"Library Path"

(2). 该选项卡上我们看到"FrameWork linkage", 默认是"Merged into cdoe"(FLEX4 默认是RSL)

(3). 点开下拉, 选择"runtime shared library(RSL)"

(4). 针对自定义的SWC ,修改其link type 为RSL ,选择None, 同时勾上Automatically extract swf to deployment path( 自动将SWF 提取到部署路径) 。如果想对不同域的RSL 共享,则选择Digests (摘要),同时指定其Policy file url (策略文件)。具体可参考FLEX SDK 中的SWC 文件处理方式。

(5). 点击OK

4. 请问SWC 是做什么用的, 怎么样自己制作一个SWC?

答:静态链接库是SWC 文件,通过编译器的library-path 和include-libraries 编译进应用程序。

新建Flex Library Object 或使用compc 命令可以制作SWC 。

5.flex 生成出来的文件都是很大, 请问你用什么办法进行缩小呢?

答:(1)RSL

(2)Module

(3) 外部加载资源

6. 请问trace( NaN == NaN ) 结果为true 还是false, 为什么?

答:NaN 具有独特的数学性质,任何与其相关的比较都会得到false 的计算结果。改用全局 isNaN() 函数检测NaN 值,如下所示:

trace(NaN == NaN); // false!

trace(NaN != NaN); // false again!

trace(isNaN(NaN)); // true

7.warning: unable to bind to property ” on class ‘Object ’ (class is not an IEventDispatcher) 在使用ItemRender 时, 经常会出现这种警告, 请问想去除的话怎么办呢?

答:ArrayCollection 的子元素是无法作为数据源绑定的。可以声明中间变量,在override set data 时将ArrayCollection 的子元素传入,然后再将中间变量作为新的绑定源即可。

8. 现在流行MVC, 但是as 代码有的时候还是大部分写在mxml 里面, 请问我想代码分离怎么办呢?

答:严格按照MVC 框架规范书写代码。如果还是不行,可以考虑重写组件或者从业务逻辑上解耦。没必要用source 引用外部as 文件来达到代码分离,那没有意义。

9. 我想继承UIComponent 重新写一个正方形的组件, 我应该怎么做? 请说重点部分即可.

答:(1) 使用get 、set 初始化组件边长等必要数据,指定能通过MXML 标记设置的属性。

(2) 如果组件内有子元素,覆盖createChildren() 方法,使用addChild 加入这些子元素。

(3) 覆盖commitProperties() 方法,提交边长等组件属性变化。

(4) 覆盖measure() 方法,设置组件缺省size 和缺省最小size 。

(5) 覆盖updateDisplayList() 方法,依据布局确定子元素大小及位置。最后,使用graphics 类的drawRect 方法画出正方形边框。

10. 常用的几个切换数据的组件比如: TabNavigator 等都有属性 creationPolicy 你知道这种策略的使用方式是什么嘛? 以及优, 缺点呢?

答:延迟实例化。优点是可以更快地加载组件,缺点是首次访问其他组件时,由于需要重新加载此组件,可能会有一定的延迟。

11. 我想在application 里获取当前运行的URL, 我要怎么获取.

答:Application.application.url

12. 请说下事件里的currentTarget 和 target 的区别?

答:在事件流的过程中,目标阶段确定的目标对象由Event 中的target 属性来记录,冒泡阶段移动的游标则由currentTarget 来记录。事件对象冒泡过程中每往上移动一级,就会克隆出一个仅与前副本currentTarget 不同的新副本。

13. 请列举下你常用的几种effects, 并说明使用原因.

答:SoundEffect ,为了播放MP3

TweenLite 很多特效

14.HBox,VBox 和canvas 有什么区别呢? 试说出其中几点

答:canvas 只有绝对布局,没有布局管理器。

HBox,VBox 则相反,没有绝对布局,只有相对布局。

15. 请问我想在list 里选中多行信息, 我要怎么做呢?

答:设置allowMultipleSelection 为true

16.Alert 里面有几个属性, 我想设置图片怎么办呢?

答:使用iconClass 属性指定图片

17. 请问你是否设置过样式呢, 我想动态设置样式怎么办呢? 如果我想在as 代码里设置样式我又要怎么办呢?

答:使用setStyle ()

18. 你能说一下UIComponent 的生命周期嘛? 以及相关的使用场合呢?

答:(1) 调用组件构造函数

(2) 设置组件属性

(3) 调用addChild() 将组件添加到父组件显示列表

(4) 组件的parent 属性设置为对父容器的引用

(5) 设置样式

(6) 组件分发preinitialize 事件

(7) 调用组件createChildren()

(8) 调用 invalidateProperties() ,invalidateSize() ,invalidateDisplayList() 失效方法,FLEX 将在下一个“渲染事件”(render event) 期间对相应的commitProperties() ,measure() , updateDisplayList() 方法进行调用。这个规则唯一例外就是当用户设置组件的height 和width 属性时, Flex 不会调用measure() 方法。也就是说,只有当组件的explicitWidth 和explicitHeight 属性是NaN 时Flex 才会调用measure() 方法。

(9) 组件分发initialize 事件。此时组件所有的子组件初始化完成,但组件尚未更改size 和布局,可以利用这个事件在组件布局之前执行一些附加的处理

(10) 在父容器上分发childAdd 事件

(11) 在父容器上分发initialize 事件

(12) 在下一个“渲染事件”(render event) 中, Flex 执行以下动作:

a. 调用组件的commitProperties() 方法

b. 调用组件的measure() 方法

c. 调用组件的layoutChrome() 方法

d. 调用组件的updateDisplayList() 方法

e. 在组件上分发updateComplete 事件

(13) 如果commitProperties() , measure() ,updateDisplayList() 方法调用了invalidateProperties() ,invalidateSize() ,invalidateDisplayList() 方法,则Flexh 会分发另外一个render 事件

(14) 在最后的render 事件发生后, Flex 执行以下动作:

a. 设置组件visible 属性使其可视

b. 组件分发creationComplete 事件,组件的大小(size) 和布局被确定,这个事件只在组件创建时分发一次

c. 组件分发updateComplete 事件。无论什么时候,只要组件的布局(layout) ,位置,大小或其它可视的属性发生变化就会分发这事件,然后更新组件来正确地显示。

19. 请问你是否发现过 flex3 里的bug 呢, 请列举一些?

答:flex Module 内存泄露,对象无法释放。

20. 列举出flex 里面的几个绑定数据对象的方式

答:对自已的类或者变量添加绑定功能:

(1) 类前使用[Bindable] 表示所有属性都支持绑定,此类必须实现IEventDispatcher 接口。

(2) 可以给变量声明前或变量getter setter 前使用[Bindable] 。如果getter 和setter 方法同名,那么给其中一个[Bindable] ,相当于给两个都用了[Bindable] 。

使用拥有绑定功能的属性:

(1) 、MXML 的{} 方式,如:{myInput.text}{myVar1+myVar2}{myBtn}

(2) 、MXML 的 方式。和{} 相同,可以多绑一,可以双向绑定。如

(3) 、AS 的mx.binding/utils.BindingUtils 类的bindProperty () 方法或bindSetter () 方法

(4) 、AS 的mx.binding.utils.ChangeWatcher 的watch () 方法

21. 请问我自己定义了一个组件, 我想在组件里的属性里设置几个默认值, 我要怎么设置呢?

答:在定义组件时,初始化组件属性时即可指定默认值。

22.callLater() 方法怎么使用, 为什么要使用这个方法呢?

答:callLater(method:Function, args:Array):void

其中method 是函数名,args 是要传入函数的参数。

callLater 指定的函数在下次刷新屏幕的时候才会执行,这可以确保在对某个对象进行操作时对象已经创建完毕。当然也可以利用这个特点来制作渐进动画。

23. 请问你是否使用过module 这种方法去做项目呢? 他的优, 缺点是什么呢? 使用组件的方式加载的话, 他的优, 缺点是什么呢?

答:优点是合理分割了主Application ,模块化开发。更小的SWF 文件体积,配合RSL 和延迟加载策略,大大减少用户等待时间。缺点就是容易引起内存泄露。

24. 目前网页里都有导航, 请问在Flex 要做导航要注意一些什么呢? 以及怎么样做呢?

答:注意默认的延迟实例化可能会导致某些对象为空。

25. 我想在一个错误的图片链接里, 定义一下默认的图片怎么做呢?

答:控制Image 的source 属性,当图片链接出现错误时,指定默认链接。

26. 请试写一个自定义的验证组件

答:

package myCompenent

{

import mx.validators.Validator;// 引用Validator 类

import mx.validators.ValidationResult;// 引用ValidationResult 类

public class myValidators extends Validator

{

public function myValidators()// 构造函数

{

super();

}

private var results:Array;// 定义一个数组,用以存储错误

// 重写验证函数

override protected function doValidation(value:Object):Array

{

var s:String = value as String;

results = [];// 清空数组

results = super.doValidation(value);// 先用继承类中的doValida tion 方法验证

if (results.length > 0)// 如果验证时有错,返回错误信息

return results;

if(s.length>6)// 自定义验证,字符长度不超过6

{

// 记录出错信息

results.push(new ValidationResult(true,”text”,”StringTooLong”, ” 字符长度超过6 了”));

}

return results;

}

}

}

27. 请说明下trigger triggerEvent 在验证组件里是什么意思, 具体怎么使用呢?

答:指定触发验证的组件和触发事件,默认是source 指定的组件和valueCommit 事件。

具体来说,多个validator 的source 对应多个组件,但它们的trigger 都指向一个提交按钮,triggerEvent 都是click 。这样,只会在点击提交按钮时,才触发所有验证。

28.ExternalInterface, LocalConnection 2 者有什么区别?

答:ExternalInterface 是Flex 和Javascript 通迅使用;

LocalConnection 可以让运行于同一台计算机的本地应用程序进行交互,使用AMF3 格式通信,兼容以前版本。

29. 你是否使用过flex 的测试工具呢? 请说明下具体是哪种, 以及使用方式, 你为什么使用这种工具?

答:没有,只听过FlexUnit ,FlexMonkey 。

30. 我能把CSS 编译成swf 嘛?

答:可以,在CSS 文件上右键选择Compile CSS to SWF 。

31. 请用as3 列举下你用过的模式

答:工厂模式,单例模式

32.Embed 绑定图片有什么缺点?

答:直接编译到swf 文件中,造成其体积过大。而且由于嵌入代码中,维护不便。

33.TitleWindow 的组件是可以拖动的, 我不想让他拖动我要怎么办呢?

答:让isPopUp 属性=false ,同时设置弹出窗口为模态窗口,禁止与其他窗口交互。

34. 你是否使用过profile, 你觉得这个工具怎么样, 优, 缺点是什么呢?

答:可以很方便地观察对象的创建和销毁,帮助检查内存泄露问题。

35. 你是否做过flex 前端的性能优化, 你觉得怎么做是比较完美的?

答:(1) 、避免容器的多级嵌套,减少相对尺寸、相对定位的使用。

(2) 、尽量使用轻量级的容器

(3) 、避免使用大体积的组件,比如DataGrid 、AdvancedDataGrid

(4) 、处理数据时多用分页的方式

(5) 、少使用setStyle

(6) 、使用延迟实例化加载子组件

36. 你是否了解E4X, 请说明一下优, 缺点?

答:E4X 是在ECMA-357 标准中定义的,并成为AS3 的一部分。优点是提供更简明和可读性强的语法从XML 中查找和提取数据。

37. 请列举一下你知道的影响性能的几个因素?

答:同上面第35 题。

38. 请说明一下ShareObject 的使用方法? 以及优, 缺点?

答:getLocal() 用来指定存储在客户端的路径。

data 属性用来指定要存储的数据内容。

flush 方法负责把数据内容写入。

clear 方法用于清除储存的信息。

39. 请列举一下, 你认为不错的网站或者blog.

答:insideRIA ,AS 天地会,AIRIA ,javeeye ,N 神,杜增强,牛牛猪研究所,黑羽

40. 我现在给你100 万做一个flex 项目, 你认为成功的要素在哪呢?

答:(1) 数据和需求等传统软件项目的成功要素

(2) 模块化开发,MVC 框架

(3)swf 文件减肥,运行效率,内存泄露问题,前台优化

(4) 开源组件的使用

转自:http://blog.csdn.net/bibishou/archive/2010/10/11/5933150.aspx

tutorial: Flex + AMFPHP + POG

Preface

If you are no stranger to the concept of a Rich Internet Application (aka. RIA) and the different constituents that make up a RIA, you can skip this introduction. This tutorial will help developers to setup a Flex application to a database using PHP while minimizing manual database queries. Let’s familiarize ourselves with a few basic RIA concepts. Generally a RIA is comprised of 3 main components:

* the client – no, not your client that sends the checks, but rather the Graphical (User) Interface that a user of a RIA interacts with. In our case, this the flex client that is deployed to a particular URL.
* the service layer -this component is the hidden part of the application that interprets client events, requests information stored on a database, and then sends the requested data back to the client. In our case AMFPHP, PHP and POG will be in this category. I will explain what these mean in a bit.
* the database – this is where our data is stored. In my case this is MySQL. Depending on your local setup, you may be using a different database.

For most of this tutorial we will be dealing with the client and the service layer. The service layer will be comprised of AMFPHP which is a very small framework which facilitates remoting between Flex and PHP. Remoting is simply a means to send and receive native ActionScript objects to a service layer. POG is another small framework for taking PHP objects and allowing CRUD methods for their database counterparts. CRUD stands for Create, Read, Update and Delete and POG simply stands for PHP Object Generator. In our case, we are setting up a RIA so that the objects sent to and from Flex will easily be able to be manipulated via CRUD methods. To sum this up we are establishing a seamless means of having Flex and a database to communicate with a minimum amount of manual data manipulation. If that confused the hell out of you, I apologize as I am kinda new to making tutorials.
Resources

POGTestApp client & server – link
AMFPHP v1.9 20070513 – link
POG – link
The Quest

Anyone who frequents this blog know that I have been on a mission for some time to get some sort of ORM setup for my pet-project. I didn’t want to be encumbered by a heavy framework with a complex API or inheritance structure. I’d looked at CakePHP, Doctrine, Propel, Junction and a few others. As a non-PHP guy, I found all of those to be overwhelming. I’d rather spend my time coding than having to read config documentation or learn a new API. That is not to say that I don’t want to learn something new, I do. I just felt enough of my time had been spent trying to find the right solution. The right solution had to be ultra-simple and intuitive.
Enter POG

POG stands for PHP Object Generator. I’ll spare you my praises of it for now (you can read up on their site if you like). Suffice it to say it is an ORM framework that is simple, intuitive and light weight. And it works for me. This looks like a long read, and it is, but it will go rather quickly. Lot’s of pictures too!!!
Your first Flex + AMFPHP + POG RIA
Server setup

I have my project setup in two places. One location is where my deployable flex content, AMFPHP and POG code goes. The other is simply where I house my Flex project source. Here is a pic of the deploy location:

picture-2.png

I use MAMP (Mac + Apache + MySQL + PHP) which is a turnkey PHP server. It works well for me because I really didn’t like doing all the Terminal setup to get my Mac’s built in PHP setup for this. If my project makes it to the big time, then all this server side setup will be delegated to a more knowledgeable person who can set it up better than I have.
AMFPHP

Firstly I want to tackle the AMFPHP part since its probably the most straight forward part of the process. Go and download AMFPHP 1.9. I am using the 20070513 release. Once downloaded, unzip it and place it in the aforementioned deploy location. The only things you need to do for AMFPHP is:

* make note of you services folder (I put a symlink to the whole AMF folder in my flex project so I could have direct access to it from within Eclipse without having to use the bin folder).
* adjust the following information on the globals.php
o $servicesPath – in my case “services/”
o $voPath – this will point to your POG objects folder once we get it setup, in my case “../pog/objects/”

That is all on the AMFPHP aside from constructing your services.

[EDIT 2008.03.21]

Since initially this tutorial only happened to touch upon the setup of these technologies there hadn’t been any issues encountered. Obviously this tutorial didn’t reflect a real implementation of such a setup beyond the simple Get method. Further development has turned up an interesting find about sending AS3 objects out from Flex to be mapped to a POG object. As it is now, it can’t. That is because the naming convention chosen by the POG framework doesn’t get picked up by the AMFPHP deserializer. My gunslinger buddy Renaun Erickson has found a simple solution for this that doesn’t break the POG naming convention. You can read more about it on his blog – link.

You need to open the AMFBaseDeserializer.php and insert the following code at line 384:

elseif(file_exists($GLOBALS['amfphp']['customMappingsPath'] . ‘class.’ . strtolower($mappedClass) . ‘.php’))
{
$include = $GLOBALS['amfphp']['customMappingsPath'] . ‘class.’ . strtolower($mappedClass) . ‘.php’;
}

POG

POG is unique in that you don’t just go and download a framework (at least not yet). If you visit POG, you are greeted with a little RIA that takes some information about the object you want to create. I decided to use the name TestObject and give it two properties: userName and password both being varchar(255). Just to reiterate, I am using the PHP5.1+ along with the POG database wrapper:

picture-3.png

Notice that I am NOT using the PDO mysql wrapper. Reason being that AMFPHP has issues finding the mysql PDO driver and not everyone’s php environment contains those. So let’s stick to the POG database wrapper.

Since this is the first interaction with POG, we want to download the full framework in addition to you new object:

dlzip.png

Then unzip the file, rename it simple as “pog” and place it in your deployment location. Next locate the {yourMainDeploymentFolder}/pog/configuration.php and update the needed information so that POG can access your database. Here is a snap of mine:

configs.png

Notice that I have my mysql port set to 8889 rather than the default 3306? Also the plugin settings url is an absolute path. In your browser navigate to the following location: http://localhost{:yourPort}/{yourMainDeploymentFolder}/pog/setup/index.php. Go through the initial welcome/setup screen. POG will do some quick unit test, and if everything goes well, you are then presented with a portal to do basic CRUD methods on your new POG object. This is useful because we can setup a few test objects to use in setting up and testing the Flex application.

Now it would appear that POG is ready to go. And you’d be correct if you just want to use the local POG portal to play with it. In order to get it working with Flex and AMFPHP, you need to fix a few things with a few classes in POG. We will come back to that after we get the Flex project setup.
Flex

I am providing my POGTestApp source for you to download, but I also want you to see the steps necessary to do it yourself. First let’s create a new Flex project. I called mine POGTestApp. Now I also have mine located in a different place than the deployment location so I used some advanced options:

flexpath.png

In the provided flex project, I have the Cairngorm.swc in the libs folder. Make sure to add the libs folder to the library path. Also point it to the services-config.xml:

picture-5.png

Open the services-config.xml and make sure to modify the endpoint uri to point to your amfphp gateway.php:

services-config.png

Now at this point you should be able to modify your Services.mxml (ServiceLocator subclass) and add your php services there. If you downloaded the files I have provided, I suggest taking a look at Services.mxml. Since this is a testing application, I have a genericFaultHandler and a genericResultHandler in this file that you can add breakpoints to for debugging purposes. So even though I am making the calls from the application file without any responders, I am still listening for them in Services.mxml. Now if you decide to make some calls of you own, without using my files, you will notice that you get some errors or it just doesn’t seem to work. That is because POG needs some adjustments to work properly.
POG adjustments

Even though POG works inside the provided POG setup.php, it won’t want to play with Flex or AMFPHP unless you give it some help. Here are a few things to modify:

* open the class.database.php and hardcode your configuration.php settings in there. For some reason the global vars are not making through to the Database class. Since I suck at php, I was advised to put it here until a better solution is found.
* open the class.testobject.php (or whatever your POG object is named) and add the remoting string: var $_explicitType = YourRemotingClassNameHere.
* also add include_once(‘class.database.php’);to class.testobject.php.

That should do it. Make your own or use the POGTestingServices and play with it. Keep in mind that even though my provided files work, you might get some PHP specific errors that appear to fail silently. If you experience this behavior you need to check your php.log to see what the issue is. Generally its due to the remoting code rather than the POG code.
Retrospective

I really like the idea of remoting for prototyping. It takes the hassle away from having to parse your responses in flex. POG is an ideal solution for developers not that familiar with PHP as the objects translate rather easily and since it is OO, its easy to do the mysql input without having to get involved with writing queries.

When time is of the essence, maybe you will consider this beautifully simple solution. Thanks goes out to Joel Wan (POG) and Renaun Erickson (the gunslinger) for help sorting this out. Let me know if you have any advice, suggestions, criticism and or corrections for this tutorial.

Possibly related posts: (automatically generated)

* CF Tutorials
* Empower Your Development Skill with the Latest Flex Actionscript 3
转自:http://jwopitz.wordpress.com/2008/03/12/tutorial-flex-amfphp-pog/

php开源项目BoTwi.无视oAuth,继续Basic推墙

Twitter完全不顾中国人民的强烈谴责,正式关闭了Http Basic Auth,只好建这个开源项目叫BoTwi:Break OAuth Twitter——帮你自建一个继续使用Basic方式的代理API。

怎么使用:

需要一个支持curl/.htaccess/无广告的PHP5空间,可以不做任何设置,上传即可用,API地址指向上传目录下的/t。

可以运行check.php检查一下主机是否支持。

为啥要用:

如果你的Twitter客户端可以自定义API,可以试试自己搭建一个,这个东西相当于自动代理oAuth的Twip,效果等于Twitter没有关闭Basic,无视oAuth,直接发送用户密码就可以获得Twitter内容。

Twip也有oAuth版本,但只支持有限的几个用户,设置麻烦,所以自己写一下。感谢Twip的作者@yegle,同时也借鉴了dabr的代码。

折腾说明:

如果你不想折腾,下面的内容可以不看——

自定义API名称:

比如你上传到了http://www.abc.com/botwi/下面,那么你在http://dev.twitter.com申请的应用的 OAUTH_CALLBACK_URL要指向http://www.abc.com/botwi/oauth,在botwi/t/config.php里 定义这个值,并按申请应用时给你的值修改OAUTH_CONSUMER_KEY和OAUTH_CONSUMER_SECRET。

更快地连接:

如果传给API的是用户名密码,那么除了几个不需要认证的search之类,一般都要自动运算一次获得oAuth授权,但如果你能让客户端发来oauth_token和oauth_token_secret,那就可以省下这一步自动运算的时间。

我自己定义了一个/takeoAuth.json,向/botwi/t/takeoAuth.json发送用户密码,你就可以得到一个json格式的oauth_token和oauth_token_secret,然后你就可以接下来都用这两个东西发送请求了。

Godaddy免费空间:

大概6块人民币可以在Godaddy买个info域名,送免费空间,用来做API性能很好,可惜json输出后面都带广告,如果你能够在客户端处理掉这个广告,比如PHP的用strip_tags可以完美去除。

其它免费空间:

Google“php免费空间”试试,目前只测过alwaysdata,在Environment的PHP配置里加上extension = curl.so就行了。

项目地址:http://code.google.com/p/botwi/

测试API:http://iamzzm.alwaysdata.net/botwi/t http://botwi.alwaysdata.net/botwi/t

PS.

http://iamzzm.alwaysdata.net http://botwi.alwaysdata.net 是使用这个API的真理部内参,原来的nc.alwaysdata.net被光荣牺牲了,但搭建一个不过几分钟的事,真不知道有关部门费这个劲干嘛,白白增加了GFW黑名单的维护成本——话说这个成本里也包含了我交的税呀。

PS.PS.

这个API代码还没有经过更全面的测试,有问题推上找我:@iamzzm

PS.PS.PS.

杯具,刚发完Twitter就维护了~在这回答点问题:

这个项目首先是鼓励迅速搭建公开可用的API,如果是私用,最新版的Twip已经满足要求,可以无视路过。

当然,如果你要让这个API也私用,很简单,在/t/index.php里的if ($type == ‘oauth’)前面加两行:

$add = (strpos ( $request_api, ‘?’ ) > 0) ? ‘&’ : ‘?’;

$request_api .= $add.’oauth_token=xxxxxxxx&oauth_token_secret=xxxxxxx’;

这里的xxxxxxx是你账号私有的token和secret。不过不鼓励这样,共享没什么不好。

9.5 update:

iamzzm.alwaysdata因主机CPU超过限制被停,应该主要在于自动oAuth的运算,只好把API和oAuth运算分开,API仍放在无广告的alwaysdata上,而oAuth运算放在godaddy的免费主机上再trim+strip_tags去广告
转自:http://hi.baidu.com/%B0%B5%BA%DA%B4%EF%C8%CB/blog/item/f180d28103762ed6bc3e1eae.html

twiteseV1.3

twitese简介¶

Twitese推特中文圈旨在帮助中国twitter使用者寻找国内优秀twitter用户,同时让大陆用户无需翻墙即可更新状态和浏览好友消息。

如果你有时间修改twitese的源程序,为它增加功能,并愿意开源,可以把修改过的程序发给我(bang590[在]gmail.com),我传到这里~希望有热心人士一起改进twitese :>
如果发现有错误 请先尝试下载SVN里的最新版本¶

下载源文件:

方法一:通过SVN工具下载:http://twitese.googlecode.com/svn/trunk/ 此下载方法可以保证下载的是最新的程序。

方法二:进入项目主页http://code.google.com/p/twitese/ 点击右边的Featured downloads下载压缩后的源程序。此方法不保证下载到最新的程序。`

下载后,打开lib/config.php,按上面的说明修改一些参数(如果使用国外空间,可跳过此步):

//twitter api地址,如果是国外空间,请用http://twitter.com,国内空间需要用第三方API proxy
define(‘API_URL’, ‘http://twitter.com’);
//“随便看看”与“排行榜”的api地址,由架设在GAE的twitese提供
define(‘TWITESE_API_URL’, ‘http://twiteseapi.appspot.com’);
//网站名称
define(‘SITE_NAME’, ‘推特中文圈’);

//加密用户名密码用的密匙,随便输入一字符串。
//需要mcrypt模块支持,如果值为空则不加密。视空间支持情况选择开启与否
define(‘SECURE_KEY’, ”);

//附加密码,如果密码不为空,登录时会要求用户输入附加密码。
define(‘TWITESE_PASSWORD’, ”);

修改完后,传到php空间,就能使用了。

Hello world!

		/**
			Determines if Array inArray contains any element of Array items.

			@param inArray: Array to search for items in.
			@param items: Array of elements to search for.
			@return Returns true if inArray contains any element of items; otherwise false.
			@example
				
					var numberArray:Array = new Array(1, 2, 3, 4, 5);
					trace(ArrayUtil.containsAny(numberArray, new Array(9, 3, 6)));
				
		*/
public static function containsAll(inArray:Array, items:Array):Boolean {
			var l:uint = items.length;

			while (l--)
				if (inArray.indexOf(items[l]) == -1)
					return false;

			return true;
		}

public static function PrarmsReplace (str:String, filter:Object):String
		{
			for (var s:String in filter) {
				str=str.replace(new RegExp("(\{)"+s+"(\})","g"),filter[s]);
			}
			return str;
		}