이 예제에서는 무대에 버튼이있는 플래시 파일을 만들었습니다. 이 버튼을 클릭하면 Flash가 단추의 이미지를 ASPX 파일로 보내어 ASPX 파일로 저장합니다. 위의 그림에서 보듯이 DisplayObject
을 BitmapData
객체로 그려서 수행하므로 버튼에 대한 참조를 DisplayObject
에서 상속되는 모든 것으로 쉽게 바꿀 수 있습니다 (페인트 응용 프로그램 용 캔버스가 포함 된 무비 클립 포함) .
먼저 플래시 요소를 살펴본 다음 .NET 백엔드를 살펴 보겠습니다.
플래시
는 ASP.NET (또는 다른 백엔드)는 제 3의 라이브러리의 몇 필요 해요로 플래시에서 다음과 같이 생성 된 이미지를 보낼 수 있습니다. 우리는 AS3 코어 라이브러리 http://code.google.com/p/as3corelib/에서 얻을 수있는 JPEG 인코더 (플래시에는 없지만 최근 버전의 Flex)가 필요합니다. 또한 와이어를 통해 데이터를 전송하기 위해 base64 인코더가 필요합니다. 동적 플래시의 플래시를 사용하겠습니다 (http://dynamicflash.com/goodies/base64/).
다운로드하여 하드 디스크에서 C : \ lib 폴더와 같은 어딘가에 추출하십시오.
새 AS3 플래시 파일을 만들고 uploader.fla으로 저장했습니다. 무대에 버튼 구성 요소를 추가하고 이름을 btnUpload으로 지정했습니다. 다음으로 ActionScript 설정을 편집하고 c : \ lib 폴더를 클래스 경로에 추가했습니다. 그런 다음 문서에 업 로더이라는 클래스 이름을 지정하고 파일을 저장했습니다.
다음으로, 나는 ActionScript 파일을 생성하고 다음 코드를 추가 :
package
{
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import flash.utils.ByteArray;
import fl.controls.Button;
import com.adobe.images.JPGEncoder;
import com.dynamicflash.util.Base64;
public class Uploader extends MovieClip
{
// Reference to the button on the stage
public var btnUpload:Button;
// Encoder quality
private var _jpegQuality:int = 100;
// Path to the upload script
private var _uploadPath:String = "/upload.aspx";
public function Uploader()
{
btnUpload.addEventListener(MouseEvent.CLICK, buttonClick);
}
private function buttonClick(e:MouseEvent):void
{
// Create a new BitmapData object the size of the upload button.
// We're going to send the image of the button to the server.
var image:BitmapData = new BitmapData(btnUpload.width, btnUpload.height);
// Draw the button into the BitmapData
image.draw(btnUpload);
// Encode the BitmapData into a ByteArray
var enc:JPGEncoder = new JPGEncoder(_jpegQuality);
var bytes:ByteArray = enc.encode(image);
// and convert the ByteArray to a Base64 encoded string
var base64Bytes:String = Base64.encodeByteArray(bytes);
// Add the string to a URLVariables object
var vars:URLVariables = new URLVariables();
vars.imageData = base64Bytes;
// and send it over the wire via HTTP POST
var url:URLRequest = new URLRequest(_uploadPath);
url.data = vars;
url.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.load(url);
}
}
}
내가 이름 Uploader.as으로 FLA 옆에이 파일을 저장.
나는 나의 Asp.NET 웹 사이트의 루트에 SWF를 발표했다. 이 코드는 100 % 품질로 jpeg를 업로드하고 데이터를받을 스크립트를 upload.aspx라고하며 사이트의 루트에 있다고 가정합니다. 내 웹 사이트의 루트에
ASP.NET 나는 upload.aspx라는 이름의 WebForm의를 만들었습니다. .aspx 파일에서 페이지 지시문과 다른 모든 내용을 제거했습니다.
이 using System;
using System.IO;
public partial class upload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Get the data from the POST array
string data = Request.Form["imageData"];
// Decode the bytes from the Base64 string
byte[] bytes = Convert.FromBase64String(data);
// Write the jpeg to disk
string path = Server.MapPath("~/save.jpg");
File.WriteAllBytes(path, bytes);
// Clear the response and send a Flash variable back to the URL Loader
Response.Clear();
Response.ContentType = "text/plain";
Response.Write("ok=ok");
}
}
같은 경로를 저장하지만,이에서 당신이 할 수 있어야로 하드 코딩 된 값이 분명히 있습니다 코드 숨김에서 다음
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="upload.aspx.cs" Inherits="upload" %>
, 나는 다음과 같은 추가 : 그것은이 같은 내용 모습입니다 필요한 모든 시스템을 만들 수 있습니다.
이 AS2 또는 AS3입니까? –
이것은 AS3입니다. – EfficionDave