由于Flex只是一种客户端技术其本身并不能直接同数据库交互,在实际的应用开发过程中Flex提供了如URLRequest、HTTPService、RemoteObject、WebService等类以实现同服务器的通讯和数据交互,下面做一些介绍和实例解析:
1、使用URLRequest向服务器发送请求,使用URLLoader接收服务器返回的数据:
URLRequest类可捕获单个 HTTP 请求中的所有信息,可以将 URLRequest 对象传递给 Loader、URLStream 和 URLLoader 类以及其他加载操作的 load() 方法以启动 URL 下载;默认情况下,传递给 url 参数的 URL 必须与执行调用的 SWF 文件在完全相同的域,包括子域。如果要从其它域中加载数据,请在承载数据的服务器上放置一个跨域策略文件。有关URLRequest详细可参看http://help.adobe.com/zh_CN/AIR/1.1/jslr/flash/net/URLRequest.html
URLVariables类主要用来在应用程序和服务器之间传输参数变量;详细查看:http://livedocs.adobe.com/flex/3_cn/langref/flash/net/URLVariables.html
URLLoader 类以文本、XML、二进制数据或 URL 编码变量的形式从 URL 返回请求的数据详细请参看:http://livedocs.adobe.com/fl ......
/*============使用==========*/
var contextmenu:ContextMenuManager=new ContextMenuManager();
contextmenu.add("最大化",menuHandle);//menuHandle处理函数
/**==================ContextMenuManager.as==========================*/
package file
{
import flash.display.InteractiveObject;
import flash.events.*;
import flash.errors.IllegalOperationError;
import flash.ui.*;
import flash.utils.getQualifiedClassName;
public class ContextMenuManager extends EventDispatcher
{
protected var menu:ContextMenu;
protected var target:InteractiveObject;
public function ContextMenuManager(target:InteractiveObject,hideBuiltInItems:Boolean=true)
{
this. ......
在开发项目时,项目越大,swf生成的体积越大,对于局域网影响不大,但是对于互联网就很头疼了。
加载一个界面要很久。一般人根本没耐性等你加载完。
为了减小swf体积,个人总结了两个办法。办法如下:
第一,尽量使用module,少量使用自定义组件,这样可以减少加载的时间
第二,使用RSL,减小swf体积。RSL使用如下:
右击你的项目----->Properties------>flex Build Path----->Library Path---->Framework linkage:
选择RSL(Runtime Shared Library)----->确定
-------------------------------------------------------------------------
在使用RSL后,运行swf时出现了SecurityError: Error #2028
: 仅限于文件系统的 SWF 文件...
后来经过查询,终于有点眉目。RSL需要network权限,必需使用浏览器浏览。
如http://192.168.1.2:8080/project/bin/Main.html ......
注意:本机必须连接互联网
效果图:
源码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" creationComplete="init()">
<mx:Panel width="620" height="455" layout="absolute" title="天气预报" fontSize="12">
<mx:HRule x="10" y="78" width="570"/>
<mx:Label x="44" y="50" text="今 天" width="67" fontWeight="bold" color="#030303"/>
<mx:Label x="474" y="50" text="后 天" width="67" fontWeight="bold" color="#030303"/>
<mx:Label x="247" y="50" text="明 天" width="67" fontWeight="bold" color="#030303"/>
<mx:Canvas x="10" y="88" width="168" height="315" borderStyle="solid" borderColor="#111AC6">
<mx:Label x="10" y="10" width="146" id="lblDate"/>
<mx:Label x="10" y="38" width="146" height="24" id="lblwd"/>
<mx:Label x="10" y="70" id="lblfl" width="146" height="29"/>
<mx:Image x="10" y="120" width="70" height="65" id="imgToday"/ ......
Ctrl-F11: 执行(Run)
F11: 除错(Debug)
Ctrl-Alt-Down: 重复目前所在编辑列(Repeat current line )
Alt-Up: 移动本列,或选择列往上移动(Move line (or selection) up )
Alt-Down: 移动本列,或选择列下往移动(Move line (or selection) down )
Ctrl-Click: 移至定义区(Go to definition (also F3) )
Ctrl-D: 删除本列(Delete line )
Alt-/: 文字自动完成(Word completion (cycles through possible matches))
Ctrl-Up: 捲轴向上(Scroll up )
Ctrl-Down: 捲轴向下(Scroll Down )
(组合键) Ctrl+Shift+L
(Activate Editor) F12
(Align Baselines) Ctrl + Alt + 8
(Align Bottom) Ctrl + Alt + 6
(Align Horizontal Centers) Ctrl + Alt + 5
(Align Left) Ctrl + Alt + 1
(Align Right) Ctrl + Alt + 3
(Align Top) Ctrl + Alt + 4
(Align Vertical Centers) Ctrl + Alt + 2
(Backward History) Alt + Left
(Breakpoints) Alt + Shift + Q,B
(Build All) Ctrl + B
(Cheat Sheets) Alt + Shift +Q,H
(Close) Ctrl + F4
(Close All) Ctrl + Shift + F4
(Console) Alt + Shift + Q,C
(Cont ......
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="initApp()"
backgroundColor="#FFFFFF">
<mx:Canvas id="paper"
x="30"
y="24"
width="1200"
height="1800">
<mx:Canvas id="LEV"
name="LEV"
x="20"
y="17"
width="120"
height="120"
borderStyle="inset">
<mx:Button x="0"
y="74"
label="关键词导出"
width="116"
height="20"
color="#1B803A"/>
<mx:Text x="0"
y="20"
width="116"
height="55"
text="List PV:10000"
fontSize=&qu ......