注意:jsp文件和swf文件都放在跟目录下,加上跨域允许访问文件。
详细编写请参考flash cs3 帮助文档,里面有完整的例子 。
1.jsp页面。
<%
...
@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"
%>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" lang ="en" xml:lang ="en" >
< head >
< title ></ title >
< meta http-equiv ="Expires" content ="Mon, 04 Dec 1999 21:29:02 GMT" />
< meta http-equiv ="PRAGMA" content ="NO-CACHE" />
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< script type ="text/javascript" src ="../../js/swfobject.js" ></ script >
< script type ="text/javascript" > ...
swfobject.registerObject("myFlashContent", "9.0.0", "expressInstall.swf");
var jsReady = false;
function isReady() ...{
return jsReady;
}
function pageInit() ...{
jsReady = true;
//document.forms["form1"].output.value += " " + "JavaScript is ready. ";
}
function thisMovie(movieName) ...{
if (navigator.appName.indexOf("Microsoft") != -1) ...{
return window[movieName];
} else ...{
return document[movieName];
}
}
function sendToActionScript(value) ...{
thisMovie("myFlashContent").sendToActionScript(value);
}
function sendToJavaScript(value) ...{
document.forms["form1"].output.value += "ActionScript says: " + value + " ";
}
</ script >
</ head >
< body onload ="pageInit();" style ="background-color:antiquewhite" >
< div style ="width:800px;height:600px;border:1px solid red;" >
< object classid ="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width ="800" height ="600" id ="myFlashContent" >
< param name ="movie" value ="cut.swf" />
<!-- [if !IE]> -->
< object type ="application/x-shockwave-flash" data ="cut.swf" width ="800" height ="600" >
<!-- <![endif] -->
< a href ="http://www.adobe.com/go/getflashplayer" >
< img src ="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt ="Get Adobe Flash player" />
</ a >
<!-- [if !IE]> -->
</ object >
<!-- <![endif] -->
</ object >
</ div >
< form name ="form1" onsubmit ="return false;" >
< input type ="text" name ="input" value ="" />
< input type ="button" value ="Send" onclick ="sendToActionScript(this.form.input.value);" />< br />
< textarea cols ="60" rows ="20" name ="output" readonly ="true" > Initializing... </ textarea >
</ form >
</ body >
</ html >
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" lang ="en" xml:lang ="en" >
< head >
< title ></ title >
< meta http-equiv ="Expires" content ="Mon, 04 Dec 1999 21:29:02 GMT" />
< meta http-equiv ="PRAGMA" content ="NO-CACHE" />
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< script type ="text/javascript" src ="../../js/swfobject.js" ></ script >
< script type ="text/javascript" > ...
swfobject.registerObject("myFlashContent", "9.0.0", "expressInstall.swf");
var jsReady = false;
function isReady() ...{
return jsReady;
}
function pageInit() ...{
jsReady = true;
//document.forms["form1"].output.value += " " + "JavaScript is ready. ";
}
function thisMovie(movieName) ...{
if (navigator.appName.indexOf("Microsoft") != -1) ...{
return window[movieName];
} else ...{
return document[movieName];
}
}
function sendToActionScript(value) ...{
thisMovie("myFlashContent").sendToActionScript(value);
}
function sendToJavaScript(value) ...{
document.forms["form1"].output.value += "ActionScript says: " + value + " ";
}
</ script >
</ head >
< body onload ="pageInit();" style ="background-color:antiquewhite" >
< div style ="width:800px;height:600px;border:1px solid red;" >
< object classid ="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width ="800" height ="600" id ="myFlashContent" >
< param name ="movie" value ="cut.swf" />
<!-- [if !IE]> -->
< object type ="application/x-shockwave-flash" data ="cut.swf" width ="800" height ="600" >
<!-- <![endif] -->
< a href ="http://www.adobe.com/go/getflashplayer" >
< img src ="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt ="Get Adobe Flash player" />
</ a >
<!-- [if !IE]> -->
</ object >
<!-- <![endif] -->
</ object >
</ div >
< form name ="form1" onsubmit ="return false;" >
< input type ="text" name ="input" value ="" />
< input type ="button" value ="Send" onclick ="sendToActionScript(this.form.input.value);" />< br />
< textarea cols ="60" rows ="20" name ="output" readonly ="true" > Initializing... </ textarea >
</ form >
</ body >
</ html >
2.flash端
package
... {
import com.wdxc.ImageCut;
import com.wdxc.ImageRotation;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.* ;
import flash.display.*;
import flash.geom.* ;
import flash.net.*;
import flash.text.TextField;
import flash.utils.ByteArray;
import com.wdxc.util.* ;
import fl.containers.ScrollPane;
import flash.display.Shape;
import fl.events.ScrollEvent;
import flash.external.ExternalInterface;
import flash.system.Security;
import flash.utils.Timer;
import flash.events.TimerEvent ;
/** *//**
* @author luqinglong
*/
public class Main extends MovieClip
...{
//存储加载进来的图片数据
private var _bitmap:Bitmap = new Bitmap() ;
//进度条
private var _progressbar:TextField ;
private var picname:String ;
private var _imageCut:ImageCut = new ImageCut() ;
//场景引用
public static var SCENE:MovieClip ;
//test
var output:TextField = new TextField();
public function Main():void ...{
SCENE = this;
//this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
//this.loaderInfo.addEventListener(Event.COMPLETE, fileCompleteHandler) ;
menu_mc.cut_btn.addEventListener(MouseEvent.MOUSE_DOWN, this._imageCut.startCutPic);
menu_mc.save_btn.addEventListener(MouseEvent.MOUSE_DOWN, save) ;
menu_mc.rotate_btn.addEventListener(MouseEvent.MOUSE_DOWN, rotationHandler) ;
menu_mc.addword_btn.addEventListener(MouseEvent.CLICK, calljs) ;
load_btn.addEventListener(MouseEvent.MOUSE_DOWN, loadPic);
startLoadPic();
this.checkAvailable();
output.y = 40;
output.width = 100;
output.height = 100;
output.multiline = true;
output.wordWrap = true;
output.border = true;
this.addChild(output) ;
}
private function rotationHandler(e:MouseEvent):void ...{
var ir:ImageRotation = new ImageRotation() ;
ir.x = menu_mc.x ;
ir.y = menu_mc.y ;
this.stage.addChild(ir);
}
... {
import com.wdxc.ImageCut;
import com.wdxc.ImageRotation;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.* ;
import flash.display.*;
import flash.geom.* ;
import flash.net.*;
import flash.text.TextField;
import flash.utils.ByteArray;
import com.wdxc.util.* ;
import fl.containers.ScrollPane;
import flash.display.Shape;
import fl.events.ScrollEvent;
import flash.external.ExternalInterface;
import flash.system.Security;
import flash.utils.Timer;
import flash.events.TimerEvent ;
/** *//**
* @author luqinglong
*/
public class Main extends MovieClip
...{
//存储加载进来的图片数据
private var _bitmap:Bitmap = new Bitmap() ;
//进度条
private var _progressbar:TextField ;
private var picname:String ;
private var _imageCut:ImageCut = new ImageCut() ;
//场景引用
public static var SCENE:MovieClip ;
//test
var output:TextField = new TextField();
public function Main():void ...{
SCENE = this;
//this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
//this.loaderInfo.addEventListener(Event.COMPLETE, fileCompleteHandler) ;
menu_mc.cut_btn.addEventListener(MouseEvent.MOUSE_DOWN, this._imageCut.startCutPic);
menu_mc.save_btn.addEventListener(MouseEvent.MOUSE_DOWN, save) ;
menu_mc.rotate_btn.addEventListener(MouseEvent.MOUSE_DOWN, rotationHandler) ;
menu_mc.addword_btn.addEventListener(MouseEvent.CLICK, calljs) ;
load_btn.addEventListener(MouseEvent.MOUSE_DOWN, loadPic);
startLoadPic();
this.checkAvailable();
output.y = 40;
output.width = 100;
output.height = 100;
output.multiline = true;
output.wordWrap = true;
output.border = true;
this.addChild(output) ;
}
private function rotationHandler(e:MouseEvent):void ...{
var ir:ImageRotation = new ImageRotation() ;
ir.x = menu_mc.x ;
ir.y = menu_mc.y ;
this.stage.addChild(ir);
}