Archive

Posts Tagged ‘Flash’

Flash中 不规则(任意形状)物体(MC)碰撞(判断是否相交)

August 18th, 2008

判断不规则物体是否相交

任意形状mc的碰撞检测  可用于FLASH游戏开发(赛车,雷电,射击(弹道式)等) Read more…

Docu~ , ,

js与flash双边通信(ExternalInterface类)

July 14th, 2008

js与flash双边通信 import flash.external.*; Read more…

Docu~ , ,

JavaScript与Flash的通信

July 10th, 2007

当Flash置于HTML容器中时,经常会遇到AS与JS的通信问题,例如:JS能否调用AS中的变量、方法,AS能否调用JS中的变量、方法等等。答案是肯定的。随着技术的不断发展,解决方案也是多种多样的。
在我总结的HTML与FLASH之间的“静态”传值一文中提到了JS使用SetVariable方法来设置FLASH中的变量,kinglong认为此法已经过时。对此我表示同意,但上文重点毕竟不是在讨论JS与AS的通信,因此另外对AS与JS通信做一个个人总结,欢迎大家讨论。
实现JS跟AS的通信,目前可选方法比较多,但早期的方法在使用便捷和功能上都不是很完美,下面做一简要说明:
Read more…

Docu~ , ,

flash+asp上传程序

February 7th, 2007

在Flash8中:

方法一:

使用file.upload可以带参数给后台的ASP程序:

file.upload(_root.iisPath+”uploadFile.asp?userName=”+_root.userName+”&uploadName=”+_root.uploadName);

后台的uploadFile.asp:


<%
userName=request(”userName”)
uploadName=request(”uploadName”)
set upload=new upload_5xSoft ”建立上传对象
set file=upload.file(”Filedata”) ”生成一个文件对象
if file.FileSize>0 then ”如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath(”.\”&userName&”\”&uploadName) ”保存文件
end if
set file=nothing
set upload=nothing ”删除此对象
%>

方法二:

不用file.upload方法,直接用LoadVars方法,简洁,好用.

FLA代码:

//上传代码
import flash.external.*;
browseBtn.onPress = function() {
_root.filePath = String(ExternalInterface.call(”getFilePath”, “Element”));
uploadTxt.text = _root.filePath;
};
uploadBtn.onPress = function() {
_root.getTime();
_root.uploadName += “.png”;
var myLoadVars:LoadVars = new LoadVars();
myLoadVars.load(_root.iisPath+”uploadFile.asp?userName=”+_root.userName+”&uploadName=”+_root.uploadName+”&filePath=”+_root.filePath);
myLoadVars.onData = function(data) {
uploadTxt.text = data;
};
};
在生成的html文件的head间插入:

在生成的html文件的body间插入:

后台的uploadFile.asp:

<%
userName= Request(”userName”)
uploadName= Request(”uploadName”)
filePath = Request(”filePath”)

Set objStream = Server.createObject(”ADODB.Stream”)
objStream.Type = 1 ” adTypeBinary
objStream.Open
objStream.LoadFromFile filePath
objStream.SaveToFile Server.MapPath(userName&”/”&uploadName)
Response.write(”上传完毕!”)
%>

在Flash9中:

方法一:

使用file.upload可以带参数给后台的ASP程序:

//获取上传文件名
parent.getTime()
var uploadURL:URLRequest;
var file:FileReference;
var fileType:String
uploadURL = new URLRequest();

//uploadURL.url = “http://127.0.0.1/upLoad/uploadFile.asp?userName=hdt&uploadName=1.jpg”
trace(parent.userName)
file = new FileReference();
file.addEventListener(Event.select, selectHandler);
file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
file.addEventListener(Event.COMPLETE, completeHandler);
function selectHandler(event:Event):void {
var file:FileReference = FileReference(event.target);
//trace(”selectHandler: name=” + file.name + ” URL=” + uploadURL.url);
uploadTxt.text = file.name;
fileType = file.type;
}
function ioErrorHandler(event:IOErrorEvent):void {
//trace(”ioErrorHandler: ” + event);
uploadTxt.text =”上传失败…”
}
function progressHandler(event:ProgressEvent):void {
var file:FileReference = FileReference(event.target);
// trace(”progressHandler: name=” + file.name + ” bytesLoaded=” + event.bytesLoaded + ” bytesTotal=” + event.bytesTotal);
uploadTxt.text =”正在上传…”
}
function completeHandler(event:Event):void {
//trace(”completeHandler: ” + event);
uploadTxt.text =”上传完毕…”
}
browseBtn.addEventListener(MouseEvent.MOUSE_DOWN,browse);
function browse(e:Event){
var imagesFilter:FileFilter = new FileFilter(”Images”, “*.jpg;*.gif;*.png”);
var docFilter:FileFilter = new FileFilter(”Documents”, “*.pdf;*.doc;*.txt”);
file.browse([imagesFilter]);
}
uploadBtn.addEventListener(MouseEvent.MOUSE_DOWN,upload);
function upload(e:Event){

uploadURL.url = parent.iisPath+”/uploadFile.asp?userName=”+parent.userName+”&uploadName=”+parent.uploadName+fileType;
file.upload(uploadURL);
}

后台ASP文件同上

方法二:

不用file.upload方法,直接传文件名:

import flash.external.ExternalInterface;
var readyTimer:Timer = new Timer(100, 0);
var uploadURL:URLRequest;
browseBtn.addEventListener(MouseEvent.MOUSE_DOWN,browse);
function browse(e:Event){
if (checkJavaScriptReady()) {
filePath = String(ExternalInterface.call(”getFilePath”));
uploadTxt.text=filePath
} else {
readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
readyTimer.start();
}
}
uploadBtn.addEventListener(MouseEvent.MOUSE_DOWN,upload);
function upload(e:Event){
//开始上传
var loader:URLLoader = new URLLoader();
configureListeners(loader);
parent.getTime()
var fileType:String=filePath.split(”.”)[1]
parent.uploadName+=”.”+fileType
var uploadPath:String=parent.iisPath+”/uploadFileForJs.asp?userName=”+parent.userName+”&uploadName=”+parent.uploadName+”&filePath=”+filePath
uploadTxt.text=uploadPath
var request:URLRequest = new URLRequest(uploadPath);
try {
loader.load(request);
} catch (error:Error) {
uploadTxt.text=error
}
}
function checkJavaScriptReady():Boolean {
var isReady:Boolean = ExternalInterface.call(”isReady”);
return isReady;
}

function timerHandler(event:TimerEvent):void {
var isReady:Boolean = checkJavaScriptReady();
if (isReady) {
readyTimer.stop();
filePath = String(ExternalInterface.call(”getFilePath”));
uploadTxt.text=filePath
}
}
function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
function completeHandler(event:Event):void {
uploadTxt.text=”上传完毕…”
}
function openHandler(event:Event):void {
uploadTxt.text=”正在上传…”
}
function progressHandler(event:ProgressEvent):void {
trace(”progressHandler loaded:” + event.bytesLoaded + ” total: ” + event.bytesTotal);
uploadTxt.text=”已上传”+int((event.bytesLoaded/event.bytesTotal)*100)+”%”
}
function securityErrorHandler(event:SecurityErrorEvent):void {
uploadTxt.text=”IO错误…”
}
function httpStatusHandler(event:HTTPStatusEvent):void {
//uploadTxt.text=”HTTP状态…”
}
function ioErrorHandler(event:IOErrorEvent):void {
trace(”ioErrorHandler: ” + event);
uploadTxt.text=”"
}

后台ASP文件同上.

html文件:




Docu~ ,

Flash 8 实现摄像头拍照 保持尺寸

October 22nd, 2006

 前几天帮朋友做一个东西用到的 code 。
因为很久不做 Flash coding 了。所以也就很少关心 Flash 8 的新的 Calss。但听大家说过有这个功能。本想从网上找段教程或 code 来做。可是发现国内还没有类似的。就只能自己动手丰衣足食了。

开始做法:
第一步:在库中建立一个视频元件,类型选择:视频(受 ActionScript 控制)。
第二步:将视频元件拖到场景中,并调整尺寸到想要的大小。并起名为“my_video”
第三步:在时间轴中粘入下边的 code。
var my_video:Video;
my_video._x=100;
my_video._y=40;
var my_cam:Camera = Camera.get();
my_cam.setMode(180, 140, 10, true);
my_video.attachVideo(my_cam);

shutter.onRelease = function() {
myBitmap = new flash.display.BitmapData(180, 240, true, 0);
myBitmap.draw(my_video);
var tempObj = _root.createEmptyMovieClip(”photo”, 100);
tempObj._x = 300;
tempObj._y = 40;
tempObj.attachBitmap(myBitmap, 1, “always”, true);
};Testing 发现有问题,拍出来照片只有 160×120 的区域有图像。并且图像变形了。 :eek: 什么地方出了问题呢?@#$%^&* (此处省略2小时 debug 时间……)
最后发现 my_video 复制到场景中调整大小时并不是改变 my_video.width 及 my_video.height 属性,而是改变 my_video._width 及 my_video._height 属性。原有视频元件的尺寸只有 160×120 。这就相当于将 my_video 作了形变。而 BitmapData.draw() 是不会考虑源元件的形变的。用官方的说法是:
引用: 源 MovieClip 对象不对此调用使用其任何舞台中转换。该源 MovieClip 对象会被视为存在于库或文件中,没有矩阵转换、没有颜色转换,也没有混合模式。如果您希望通过使用影片剪辑自身的 transform 属性来绘制影片剪辑,则可以使用它的 Transform 对象来传递各种 transformation 属性。
我开始没注意他给出的解决办法。我想既然 draw() 不考虑源元件的形变,那只能自己在输出的照片元件上想办法做形变了。于是有了这段 code。
var my_video:Video;
my_video._x=100;
my_video._y=40;
var my_cam:Camera = Camera.get();
my_cam.setMode(180, 140, 10, true);
my_video.attachVideo(my_cam);

shutter.onRelease = function() {
myBitmap = new flash.display.BitmapData(160, 120, true, 0);
myBitmap.draw(my_video);
var tempObj = _root.createEmptyMovieClip(”photo”, 100);
tempObj._x = 300;
tempObj._y = 40;
tempObj._width= 180;
tempObj._height = 240;
tempObj.attachBitmap(myBitmap, 1, “always”, true);
};这下照片是想要的大小了,而且图像也没有了变形。但发现图像没有摄像头显示的清晰。
想了一下,那是当然,draw() 不考虑源元件的形变,draw时my_video 被当作 160×120 来draw了。 :mad: 那能不能通过改变 my_video.width 及 my_video.height 属性来改变 my_video 的尺寸而不是将 my_video 作形变呢?不能!!!my_video.width 及 my_video.height 属性是只读属性。

解决方法:
第一步:用视频编辑软件制作一个 180×240 尺寸的1贞的白色 mov 视频文件。
第二步:用 Macromedia Flash 8 Video Encoder 将mov视频文件转为 flv 视频文件。
第三步:在库中建立一个视频元件,类型选择:嵌入(与时间轴同步)。
第四步:将视频元件拖到场景中,并起名为“my_video”
Testing 发现 my_video.width 及 my_video.height 属性为 180×120 。阿哈 :cool: 第五步:在时间轴中粘入下边的 code 。
var my_video:Video;
my_video.clear()
my_video._x=100;
my_video._y=40;
var my_cam:Camera = Camera.get();
my_cam.setMode(180, 140, 10, true);
my_video.attachVideo(my_cam);

shutter.onRelease = function() {
myBitmap = new flash.display.BitmapData(160, 120, true, 0);
myBitmap.draw(my_video);
var tempObj = _root.createEmptyMovieClip(”photo”, 100);
tempObj._x = 300;
tempObj._y = 40;
tempObj._width= 180;
tempObj._height = 240;
tempObj.attachBitmap(myBitmap, 1, “always”, true);
};好了,现在所有问题都解决了。 ;)

Docu~ , , ,

逐个Load完所有的外部文件后才播放[Flash]

October 16th, 2006

参考页面 http://www.muchina.com/intro/intro_2006.htm

1.开始当然是要stop()第一帧;
Read more…

Docu~ , ,

优化FLASH的loading 根据下载速度以及剩余时间判断是否开始

October 15th, 2006

这个问题早就想过,一般加载FLASH都是加载100%才能点击 开始播放
FLASH在播放的同时是可以下载的,也就是说FLASH即使没有加载100%,只加载了一部分就可以开始播放,播放的同时下载剩余的部分。 Read more…

TurnOver ,

吕聪贤flash动画基础教程[向新手推荐]

September 8th, 2006

吕聪贤flash动画基础教程
虽然是MX 但 还是很适合新手入门 建立FLASH基础概念 思维理念 Read more…

Docu~ , , , ,

不要担心搜索引擎的蜘蛛被 框架和动画 拦住

July 17th, 2006

1`不用怕因为框架页面 而使搜索引擎的蜘蛛无法检索到你的站内页面
只要在

后面加入以下的 html代码
< noframes><meta HTTP-EQUIV=”refresh” CONTENT=”5; URL=你不含框架的索引页面(包含框架子页的链接)”>
这样搜索引擎会检索到你的框架子页 咯2`不用怕因为FLASH做导航 而使搜索引擎的蜘蛛无法检索到你的站内页面
看看国外的技术文章
应用了一个外部JS 地址是
http://blog.deconcept.com/swfobject/swfobject.js
你当下来 看看
[code]

文字导航

[/code]

在浏览器不支持FLASH或版本不够的时候 会显示文字导航,否则就显示FLASH导航
当然搜索引擎会检索你的文字导航

很简单就处理了

可以到一些国外的大型网站看看 他们的FLASH多数都是这么用的
详细使用方法 可以参看 《SWFObject: Javascript Flash Player detection》

Docu~ , , ,

SWFObject: Javascript Flash Player detection

July 17th, 2006

Using SWFObject is easy. Simply include the swfobject.js Javascript file, then use a small amount of Javascript on your page to embed your Flash movie. Here is an example showing the minimum amount of code needed to embed a Flash movie:
[code]

This text is replaced by the Flash movie.


[/code]

Here is a breakdown of what the code does:
[code]

[...]

[/code]

Prepare an HTML element that will hold our Flash movie. The content placed in the ‘holder’ element will be replaced by the Flash content, so users with the Flash plug-in installed will never see the content inside this element. This feature has the added bonus of letting search engines index your alternate content.
[code]
var so = new SWFObject(”movie.swf”, “mymovie”, “200″, “100″, “7″, “#336699″);[/code]

Create a new SWFObject and pass in the required parameters:

swf - The file path and name to your swf file.
id - The ID of your object or embed tag. The embed tag will also have this value set as it’s name attribute for files that take advantage of swliveconnect.
width - The width of your Flash movie.
height - The height of your Flash movie.
version - The required player version for your Flash content. This can be a string in the format of ‘majorVersion.minorVersion.revision’. An example would be: “6.0.65″. or you can just require the major version, such as “6″.
background color - This is the hex value of the background color of your Flash movie.

so.write(”flashcontent”);

Tell the SWFObject script to write the Flash content to the page (if the correct version of the plug-in is installed on the user’s system) by replacing the content inside the specified HTML element.

Passing variables into your movies using the “Flashvars” parameter:

[code][/code]

swfobject.js

[code]/**
* SWFObject v1.4.2: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
*
* SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
* **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
* legal reasons.
*/
if(typeof deconcept==”undefined”){var deconcept=new Object();}
if(typeof deconcept.util==”undefined”){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil==”undefined”){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){
if(!document.getElementById){return;}
this.DETECT_KEY=_b?_b:”detectflash”;
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute(”swf”,_1);}
if(id){this.setAttribute(”id”,id);}
if(w){this.setAttribute(”width”,w);}
if(h){this.setAttribute(”height”,h);}
if(_5){this.setAttribute(”version”,new deconcept.PlayerVersion(_5.toString().split(”.”)));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();
if(c){this.addParam(”bgcolor”,c);}
var q=_8?_8:”high”;
this.addParam(”quality”,q);
this.setAttribute(”useExpressInstall”,_7);
this.setAttribute(”doExpressInstall”,false);
var _d=(_9)?_9:window.location;
this.setAttribute(”xiRedirectUrl”,_d);
this.setAttribute(”redirectUrl”,”");
if(_a){this.setAttribute(”redirectUrl”,_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){_16.push(key+”=”+_18[key]);}
return _16;
},getSWFHTML:function(){
var _19=”";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute(”doExpressInstall”)){this.addVariable(”MMplayerType”,”PlugIn”);}
_19=”

_19+=” id=\”"+this.getAttribute(”id”)+”\” name=\”"+this.getAttribute(”id”)+”\” “;
var _1a=this.getParams();
for(var key in _1a){_19+=key+”=\”"+_1a[key]+”\” “;}
var _1c=this.getVariablePairs().join(”&”);
if(_1c.length>0){_19+=”flashvars=\”"+_1c+”\”";}
_19+=”/>”;
}else{if(this.getAttribute(”doExpressInstall”)){
this.addVariable(”MMplayerType”,”ActiveX”);}
_19=”“;
_19+=”“;
var _1d=this.getParams();
for(var key in _1d){_19+=”“;}
var _1f=this.getVariablePairs().join(”&”);
if(_1f.length>0){_19+=”“;}
_19+=”
“;}
return _19;
},write:function(_20){
if(this.getAttribute(”useExpressInstall”)){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute(”version”))){
this.setAttribute(”doExpressInstall”,true);
this.addVariable(”MMredirectURL”,escape(this.getAttribute(”xiRedirectUrl”)));
document.title=document.title.slice(0,47)+” - Flash Player Installation”;
this.addVariable(”MMdoctitle”,document.title);}}
if(this.skipDetect||this.getAttribute(”doExpressInstall”)||this.installedVer.versionIsValid(this.getAttribute(”version”))){
var n=(typeof _20==”string”)?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();
return true;
}else{
if(this.getAttribute(”redirectUrl”)!=”"){document.location.replace(this.getAttribute(”redirectUrl”));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(){
var _23=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,”").replace(/(\s+r|\s+b[0-9]+)/,”.”).split(”.”));}
}else{
try{var axo=new ActiveXObject(”ShockwaveFlash.ShockwaveFlash.7″);}
catch(e){try{
var axo=new ActiveXObject(”ShockwaveFlash.ShockwaveFlash.6″);
_23=new deconcept.PlayerVersion([6,0,21]);
axo.AllowScriptAccess=”always”;}
catch(e){
if(_23.major==6){return _23;}}try{axo=new ActiveXObject(”ShockwaveFlash.ShockwaveFlash”);}
catch(e){}}
if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable(”$version”).split(” “)[1].split(”,”));}}
return _23;};
deconcept.PlayerVersion=function(_27){
this.major=_27[0]!=null?parseInt(_27[0]):0;
this.minor=_27[1]!=null?parseInt(_27[1]):0;
this.rev=_27[2]!=null?parseInt(_27[2]):0;
};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major
if(this.major>fv.major){return true;}
if(this.minor
if(this.minor>fv.minor){return true;}
if(this.rev
return true;
};
deconcept.util={getRequestParameter:function(_29){
var q=document.location.search||document.location.hash;
if(q){
var _2b=q.substring(1).split(”&”);
for(var i=0;i<_2b.length;i++){
if(_2b[i].substring(0,_2b[i].indexOf(”=”))==_29){
return _2b[i].substring((_2b[i].indexOf(”=”)+1));}}}
return “”;}};
deconcept.SWFObjectUtil.cleanupSWFs=function(){
var _2d=document.getElementsByTagName(”OBJECT”);
for(var i=0;i<_2d.length;i++){
_2d[i].style.display=”none”;
for(var x in _2d[i]){if(typeof _2d[i][x]==”function”){_2d[i][x]=null;}}}};
if(typeof window.onunload==”function”){
var oldunload=window.onunload;
window.onunload=function(){
deconcept.SWFObjectUtil.cleanupSWFs();
oldunload();};
}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}
if(Array.prototype.push==null){
Array.prototype.push=function(_30){
this[this.length]=_30;
return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject; // for legacy support
var SWFObject=deconcept.SWFObject;

[/code]

Docu~ , ,