플래시 와 백 스테이지 데이터 교환 방법 정리
11240 단어 플래시 와 백 스테이지 데이터 교환 방법 정리
//=======================================================;
// Flash ;
//=======================================================;
// LoadVars ;
var data_lv = new LoadVars();
// ;
data_lv.username = "kinglong";
// ;
data_lv.password = "king";
// ;
data_lv.onLoad = function(success){
//success, ;
// , ;
if(success){
trace(" !");
//result !
if(this.result=="true"){
trace("yes");
}else{
trace("no");
}
}else{
trace(" !");
}
}
// ;
// ;
// ( LoadVars );
// ( html form , "post" "get" )
data_lv.sendAndLoad("http://www.klstudio.com/save.asp",data_lv,"post");
//=======================================================;
// ;
//=======================================================;
// flash ;
Request("username") flash username "kinglong";
Request("password") flash password "kinglong";
.... .....
//
&result=true
//
&result=false
// ,&result flash result ;
// , &result=xxx&result1=xxx ;
, flash !
XML , flash !
LoadVars 방식 의 장점: 1.플래시 코드 는 실현 이 간단 하고 편리 하 다. 2.서버 수신 페이지 는 폼 을 받 은 데이터 와 같이 처리 되 며 전문 적 인 기술 이 필요 없 이 모든 서버 프로그램 이 실 현 됩 니 다! LoadVars 방식 의 단점: 1.전달 하 는 변수 가 너무 많 으 면 안 됩 니 다. 2.변수 가 전달 하 는 값 이 너무 길 어 서 는 안 됩 니 다. 3.변수 전달 값 은'문자열'이라는 데이터 형식 만 사용 할 수 있 고 데이터 형식 이 단일 합 니 다. 4.데이터 반환 값 에"&"문자 가 있 을 수 없 기 때문에 복잡 한 반환 값 은 모두 URL 인 코딩 처 리 를 해 야 합 니 다.2.Flash RemotingFlash Remoting 이라는 데이터 인 터 페 이 스 는 네 개 중에서 효율 이 가장 높다! 그 장점: 1.데이터 형식 이 비교적 많 음Converting from application server data types to ActionScript을 지원 합 니 다. 2.전달 데이터 의 양 이 비교적 크다. 3.운행 효율 은 기 존의 몇 개 중에서 가장 높다. 4.각종 백 스테이지 에 대한 지원 도 비교적 좋다. 5.디 버 깅 모듈(NetConnection)도 있다. Debugger)
================================================================
Flash :( as1.0 , MM )
================================================================
// Remoting Component , ;
#include "NetServices.as"
// Remoting , , NetConnection Debugger ;
#include "NetDebug.as"
if (inited == null){
inited = true;
// ;
NetServices.setDefaultGatewayUrl("http://localhost:8500/flashservices/gateway");
// ;
gateway_conn = NetServices.createGatewayConnection();
// ;
myService = gateway_conn.getService("myservice", this);
}
// ;
function getString(name){
// Remoting getString ;
myService.getString(name);
}
// ;
function getString_Result(result){
//result ;
trace(result);
}
// , ;
function getString_Status(error){
trace("getString_Status");
trace(error.code);
trace(error.description);
trace(error.details);
}
// ;
getString("kinglong");
주의:결과 가 데이터 세트 로 되 돌아 오 면 모든 필드 이름 은 대문자 로 써 야 합 니 다.서버 에서 대문자 로 쓰 든 말 든!
================================================================
( Coldfusion Component , )
================================================================
<!--- myservice.cfc--->
<cfcomponent displayname=" ">
<!--- getString , access remote, Flash remoting --->
<cffunction name="getString" access="remote" returntype="string">
<cfargument name="name" type="string" required="true">
<cfset myResult = arguments.name & ", !">
<cfreturn myResult>
</cffunction>
</cfcomponent>
호출 할 때 cfc 경로 뒤에'?편리 하 죠? :) 4.XMLsocket XMLsocket 은 주로 서버 와 실시 간 통신 을 하 는 데 사용 되 는데 현재 의 응용 분 야 는 주로 Flash 텍스트 채 팅 과 Flash 온라인 게임 등 분야 입 니 다. XMLsocket 의 장점: 1.서버 와 실시 간 으로 통신 할 수 있 습 니 다. 2、Flash Player 5.0 이상 의 버 전 내 장 된 클래스 로 구성 요소 나 플러그 인 을 따로 설치 할 필요 가 없습니다. 3.XMLsocket 은 하나의 Socket 클 라 이언 트 에 해당 하기 때문에 일반적인 미들웨어 는 모두 지원 합 니 다(예 를 들 어 자바,Net 등). XMLsocket 의 단점: 1.XMLsocket 은 문자열 이나 xml 형식의 텍스트 만 전송 할 수 있 고 데이터 형식 이 단일 합 니 다. 2.XMLsocket 서버 가 자체 개발 하면 Socket 기술 에 대해 잘 알 아야 합 니 다.인터넷 에 기 존의 서버 소프트웨어(상업 적 XMLsocket)가 있 기 때 문 입 니 다. Server Unity,Fortress 가 있 습 니 다.오픈 소스 XMLsocket Server Oregano 있어 요. Multiuser Server); 3.그리고 XMLsocket 의 80 포트 와 플래시 보안 정책 문제 입 니 다.(인터넷 에 해결 방법 이 있 습 니 다.가능 한 지 모 르 겠 습 니 다.
//=======================================;
// Flash ;
// WebServiceConnector , 。
// WebService 。
// WebServiceConnector , 。
//=======================================;
stop();
// WebService ;
import mx.services.WebService;
// WebService ;
var ws_url:String = http://localhost:8500/klstudio/myservice.cfc?wsdl;
// WebService ;
var ws:WebService = new WebService(ws_url);
// WebService ;
var callObject = ws.getSting("kinglong");
// ;
callObject.onResult = function(result){
trace("result:"+result);
}
// ( );
callObject.onFault = function(fault){
trace("fault:"+fault.faultstring);
}
5.FlashCom(FMS)FlashCom(FMS)은 주로 서버 와 스 트 리밍 통신 을 하 는 데 사 용 됩 니 다.현재 응용 분 야 는 Flash 스 트 리밍,Flash 온라인 생방송,Flash 영상 오디 오 채 팅,Flash 영상 회의,Flash 온라인 게임 등 입 니 다.FlashCom 의 운영 환경(FMS 의 운영 환경):1,Windows 운영 체제:Windows 2000 서버 또는 Windows NT 4.0 Server(sp6); 2.Linux 운영 체제:Red Hat Linux 7.3 혹은 8.0; 3.서버 의 CPU 는 Pentium III 500 MHz 혹은 더 높 음. 4 CPU); 4.서버 의 메모 리 는 256 M 입 니 다. RAM 아니면 더 높 아 요.FlashCom(FMS)의 장점:1.실시 간 영상 오디 오 통신 을 실현 할 수 있 습 니 다(물론 텍스트 통신 도 지원 합 니 다).2.흐 르 는 미디어 를 동시 재생 할 수 있다(온라인 생방송 이 라 고도 부른다).3、Flash 를 통 해 Player(6.0 이상 버 전)는 비디오 오디 오 를 녹음 하고 다른 클 라 이언 트 가 필요 하지 않 습 니 다.4.클 라 이언 트 간 의 통 제 를 실현 할 수 있 습 니 다(예 를 들 어 회의 사회자 권한).FlashCom(FMS)의 단점:1.FlashCom(FMS)서버 소프트웨어 는 MM 회사 의 제품 으로 은 을 써 서 사 야 하 는(적지 않 은 투입)입 니 다.다행히 현재 보완 중인 오픈 소스 프로젝트 인 RED 5 가 있 습 니 다.2.스 트림 미디어 서버 소프트웨어 이기 때문에 서버 의 대역 폭,메모리,그리고 CPU 에 대한 요구 도 매우 높다(위 에서 설명 했다).3.동시 온라인 동 영상 통신 의 인원 이 너무 많 으 면 안 됩 니 다. 프로그램 코드//=============================================;/ 플래시 클 라 이언 트(간단 한 온라인 녹화 영상의 경우)//====================================stop(); var nc:NetConnection = new NetConnection(); var ns:NetStream; var cam:Camera = Camera.get(); var mic:Microphone = Microphone.get(); //로 컬 카메라 영상 미리 보기;video_box.attachVideo(cam); //NetStream 초기 화;function initNetStream():Void { ns = new NetStream(nc); //버퍼 시간 2 초 설정 하기;ns.setBufferTime(2); //NetStream 으로 비디오 와 오디 오 대상 불 러 오기;ns.attachVideo(cam); ns.attachAudio(mic); //NetStream 상태 정보;ns.onStatus = function(info:Object) { trace("ns.onStatus:"+info.code); }; } //비디오 오디 오 녹음 하기;function recordStream(){ ns.publish("kinglong","record"); } //녹화 중지;function stopStream(){ ns.close(); } //비디오 오디 오 파일 삭제 하기;function deleteStream(){ nc.call("clearStream",null,"kinglong"); } //NetConnection 상태 정보;nc.onStatus = function(info:Object) { trace("nc.onStatus:"+info.code); switch (info.code) { case "NetConnection.Connect.Success" : initNetStream(); break; } }; //FlashCom 서버 nc.connect 연결("rtmp:/"+"recordstream"); 프로그램 코드//=============================================;/ FlashCom(FMS)서버 코드//다음 코드 를 main.asc 파일(이 파일 이름 고정)로 저장 하고 FlashCom 의 applications 디 렉 터 리 에 recordstream 디 렉 터 리(클 라 이언 트 에 대응 하 는'recodstream')를 만 들 고 main.asc 를 이 디 렉 터 리 에 넣 습 니 다./======================================application.onAppStart = function(){ } application.onAppStop = function(){ } application.onConnect = function(client){ application.acceptConnection(client); } application.onDisconnect = function(client){ } //=======================================; //flv 파일 가 져 오 는 시간;function getStreamLength(name) { return Stream.length(name);; } //=======================================; //flv 파일 삭제 하기;function clearStream(name) { trace("clearStream("+name+");"); var stream = Stream.get(name); return stream.clear(); } //=======================================; //Client.prototype 설정;//=========================================Client.prototype.getStreamLength = getStreamLength; Client.prototype.clearStream = clearStream; FMS 공식 중국어 사이트 관련 자료 주소 추가:http://www.macromedia.com/cn/software/flashmediaserver/productinfo/pricing/