最近看到RIA比较火,也想凑个热闹,把最近几天的学习心得记录下来
给自己看,如果能对新人有所帮助那是最好的,老手就不用看了
开发环境
flash cs3 professional 和flex 3比较
flex 3 比较符合程序员的习惯,尤其是对Java程序员来说,Eclipse 太熟悉了,不过我觉得不能开发多帧的程序是flex 的最大缺点,也可能我孤陋寡闻,没找到开发多帧程序的方式
因为是新手上路,所以弄了几个非常简单的小东西,但弄来弄去还是单帧,不爽
还是选了flash cs3 虽然不符合程序员的习惯,但多帧对我吸引力太大了,因为那样才是真正的应用程序式的开发。
下面主要就flash cs3中开发写一点心得:
1、最开始最大的困难就是不知道脚本和动画如何联系起来,其实很简单,先建个flash (as3)文件,保存为ConnectSrv.fla(名字自己起),再建一个同名的as3文件,保存为ConnectSrv.as ,然后在ConnectSrv.fla 的界面上“属性面板“有个文档类:里面添上ConnectSrv就把动画和脚本联系起来了。
2、在程序中调用按钮,要打开“窗口“菜单里面的“组件“窗口,快捷键是Ctrl+F7在user interface中找到Button 然后拖到右边的库中,才能在程序中调用fl.controls.Button 因为这个小东西是组件。
3、下面做个Flash|+ JavaServlet的小的通讯Demo
as代码如下:
package{
import flash.display.Sprite;
import flash.text.TextField;
import fl.controls.Button;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.net.URLRequestMethod;
import flash.net.URLLoaderDataFormat;
import flash.events.IEventDispatcher;
import flash.net.URLVariables;
public class ConnectSrv extends Sprite{
public var connectBtn:Button;
public var msg:TextField;
public var _loader:URLLoader;
public function ConnectSrv(){
connectBtn = new Button();
connectBtn.x = 50;
connectBtn.y = 150;
connectBtn.addEventListener(MouseEvent.CLICK,onClickConBtn); //按钮的消息处理
addChild(connectBtn);
msg = new TextField();
msg.x = 100;
msg.y = 200;
msg.text = "成功啦"
addChild(msg);
}
public function onClickConBtn(e:MouseEvent){
_loader = new URLLoader();
_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
configListeners(_loader);
var par:URLVariables = new URLVariables();
par.username = "alvetjook";
par.password = "2222";
var req:URLRequest = new URLRequest("http://localhost:8080/flashT/Rev");
req.data = par;
req.method = URLRequestMethod.GET;
try {
_loader.load(req);
}catch(error:Error){
msg.text = "出错了";
}
}
public function configListeners(dispatcher:IEventDispatcher):void{
dispatcher.addEventListener(Event.COMPLETE,loadHandler);
}
public function loadHandler(e:*):void{
switch (e.type){
case Event.COMPLETE:
msg.text = "完成";
break;
}
}
}
}
import flash.display.Sprite;
import flash.text.TextField;
import fl.controls.Button;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.net.URLRequestMethod;
import flash.net.URLLoaderDataFormat;
import flash.events.IEventDispatcher;
import flash.net.URLVariables;
public class ConnectSrv extends Sprite{
public var connectBtn:Button;
public var msg:TextField;
public var _loader:URLLoader;
public function ConnectSrv(){
connectBtn = new Button();
connectBtn.x = 50;
connectBtn.y = 150;
connectBtn.addEventListener(MouseEvent.CLICK,onClickConBtn); //按钮的消息处理
addChild(connectBtn);
msg = new TextField();
msg.x = 100;
msg.y = 200;
msg.text = "成功啦"
addChild(msg);
}
public function onClickConBtn(e:MouseEvent){
_loader = new URLLoader();
_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
configListeners(_loader);
var par:URLVariables = new URLVariables();
par.username = "alvetjook";
par.password = "2222";
var req:URLRequest = new URLRequest("http://localhost:8080/flashT/Rev");
req.data = par;
req.method = URLRequestMethod.GET;
try {
_loader.load(req);
}catch(error:Error){
msg.text = "出错了";
}
}
public function configListeners(dispatcher:IEventDispatcher):void{
dispatcher.addEventListener(Event.COMPLETE,loadHandler);
}
public function loadHandler(e:*):void{
switch (e.type){
case Event.COMPLETE:
msg.text = "完成";
break;
}
}
}
}