Flex 내 remote, http, url 에 대한 재 패키지
구성 요소 코드:
package pizazz.flex4.remote{
import flash.events.Event;
import flash.events.IOErrorEvent;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.remoting.RemoteObject;
public class Conn{
protected function connFault(event:Event):void{
var _errInfo:String = " : " + event.target + "
";
_errInfo += " : " + event.type + "
";
if(event is FaultEvent){
_errInfo += " : " +
(event as FaultEvent).fault.faultCode + "
";
_errInfo += " : " +
(event as FaultEvent).fault.faultString + "
";
_errInfo += " : " +
(event as FaultEvent).fault.faultDetail;
}
Alert.show(_errInfo, " ");
}
/**
*
* @param address
* @param result
* @param config
* @param fault
* @return
*/
internal function conn(address:String, result:Function,
config:Object = null, fault:Function = null):Object{
return null;
}
}
}
package pizazz.flex4.remote{
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
import pizazz.flex4.utility.ParamUtil;
public class RemoteConn extends Conn{
private var _remote:RemoteObject;
public function RemoteConn(){
_remote = new RemoteObject();
}
override internal function conn(address:String, result:Function,
config:Object = null, fault:Function = null):Object{
ParamUtil.setParam(_remote, config);
_remote.destination = address;
_remote.addEventListener(ResultEvent.RESULT, result);
_remote.addEventListener(FaultEvent.FAULT,
function(event:FaultEvent):void{
if(fault != null){
fault(event);
}else{
connFault(event);
}
}
);
return _remote;
}
public static function getRemote(destination:String, result:Function = null,
config:Object = null, fault:Function = null):RemoteObject{
return new RemoteConn().conn(destination, result, config, fault)
as RemoteObject;
}
}
}
package pizazz.flex4.remote{
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import pizazz.flex4.utility.ParamUtil;
public class HttpConn extends Conn{
private var _http:HTTPService;
public function HttpConn(){
_http = new HTTPService();
}
override internal function conn(address:String, result:Function,
config:Object = null, fault:Function = null):Object{
ParamUtil.setParam(_http, config);
_http.url = address;
_http.addEventListener(ResultEvent.RESULT, result);
_http.addEventListener(FaultEvent.FAULT,
function(event:FaultEvent):void{
if(fault != null){
fault(event);
}else{
connFault(event);
}
}
);
return _http;
}
public static function getRemote(url:String, result:Function,
config:Object = null, fault:Function = null):HTTPService{
return new HttpConn().conn(url, result, config, fault)
as HTTPService;
}
}
}
package pizazz.flex4.remote{
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import pizazz.flex4.utility.ParamUtil;
public class UrlConn extends Conn{
private var _request:URLRequest;
public function UrlConn(){
_request = new URLRequest();
}
override internal function conn(address:String, result:Function,
config:Object = null, fault:Function = null):Object{
_request.url = address;
var _loader:URLLoader = new URLLoader();
ParamUtil.setParam(_loader, config);
_loader.addEventListener(Event.COMPLETE, result);
_loader.addEventListener(IOErrorEvent.IO_ERROR,
function(event:IOErrorEvent):void{
if(fault != null){
fault(event);
}else{
connFault(event);
}
}
);
_loader.load(_request);
return _request;
}
public static function getRemote(url:String, result:Function,
config:Object = null, fault:Function = null):URLLoader{
return new UrlConn().conn(url, result, config, fault)
as URLLoader;
}
}
}
구성 요소 실행:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600">
<s:layout>
<s:HorizontalLayout />
</s:layout>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import pizazz.flex4.remote.HttpConn;
import pizazz.flex4.remote.RemoteConn;
import pizazz.flex4.remote.UrlConn;
private function remote():void{
HttpConn.getRemote("config.xml",
function(event:ResultEvent):void{
//result
}
, {"resultFormat": "e4x"}).send({"id": 0});
RemoteConn.getRemote("service",
function(event:ResultEvent):void{
//result
}
, null,
function(event:FaultEvent):void{
Alert.show("ERROR");
}
).getOperation("method").send({"id": 0});
UrlConn.getRemote("http://127.0.0.1:8080/index",
function(event:Event):void{
}
);
}
]]>
</fx:Script>
<s:Button width="100" label=" " click="remote()" />
</s:Application>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
AS를 통한 Module 개발1. ModuleLoader 사용 2. IModuleInfo 사용 ASModuleOne 모듈...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.