点击鼠标右键..想实现图片保存和文字的复制
2009-05-28 21:19
633 查看
DownloadableImage.as
package
{
import flash.events.ContextMenuEvent;
import flash.net.FileReference;
import flash.net.URLRequest;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import mx.controls.Image;
import mx.core.Application;
public class DownloadableImage extends Image
{
public function DownloadableImage()
{
super();
}
override protected function createChildren():void
{
super.createChildren();
addDownloadContextMenu();
}
private function addDownloadContextMenu():void
{
contextMenu = new ContextMenu();
var item:ContextMenuItem = new ContextMenuItem("save as");
contextMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
}
private var fr:FileReference = new FileReference();
private function menuItemSelectHandler(event:ContextMenuEvent):void
{
if(event.currentTarget.caption == "save as")
{
if(source is String)
{
if(String(source).indexOf("http") > -1)
{
fr.download(new URLRequest(String(source)));
}
else
{
var pattern:RegExp = /(?P<protocol>http|https):\/\/(?P<host>[^\/]+)/;
var matches:Array = String(Application.application.url).match(pattern);
if(matches && matches.length > 0)
fr.download(new URLRequest(matches.protocol + "://" + matches.host + "/" + String(source)));
}
}
}
}
}
}
DownloadableImageDemo.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
<local:DownloadableImage source="DownloadableImageDemo-picture.jpg"/>
</mx:Application>
demo:
http://hydra1983.googlepages.com/DownloadableImageDemo.html
package
{
import flash.events.ContextMenuEvent;
import flash.net.FileReference;
import flash.net.URLRequest;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import mx.controls.Image;
import mx.core.Application;
public class DownloadableImage extends Image
{
public function DownloadableImage()
{
super();
}
override protected function createChildren():void
{
super.createChildren();
addDownloadContextMenu();
}
private function addDownloadContextMenu():void
{
contextMenu = new ContextMenu();
var item:ContextMenuItem = new ContextMenuItem("save as");
contextMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
}
private var fr:FileReference = new FileReference();
private function menuItemSelectHandler(event:ContextMenuEvent):void
{
if(event.currentTarget.caption == "save as")
{
if(source is String)
{
if(String(source).indexOf("http") > -1)
{
fr.download(new URLRequest(String(source)));
}
else
{
var pattern:RegExp = /(?P<protocol>http|https):\/\/(?P<host>[^\/]+)/;
var matches:Array = String(Application.application.url).match(pattern);
if(matches && matches.length > 0)
fr.download(new URLRequest(matches.protocol + "://" + matches.host + "/" + String(source)));
}
}
}
}
}
}
DownloadableImageDemo.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
<local:DownloadableImage source="DownloadableImageDemo-picture.jpg"/>
</mx:Application>
demo:
http://hydra1983.googlepages.com/DownloadableImageDemo.html
相关文章推荐
- js实现点击后将文字或图片复制到剪贴板的方法
- js实现点击后将文字或图片复制到剪贴板的方法
- 基于jquery实现一张图片点击鼠标放大再点缩小
- 基于jquery实现一张图片点击鼠标放大再点缩小
- css3实现图片遮罩效果鼠标hover以后出现文字
- 最简单的代码实现禁止鼠标右键及选中网页中的文字,支持Firefox,亲测可用
- js实现鼠标悬停文字上显示图片
- social.framework 实现分享文字图片等到新浪微博,twitter,facebook,保存和打印。
- jQuery实现点击按钮文字变成input框点击保存变成文字
- JS小功能,鼠标经过标签时悬浮层提示+点击可复制文字
- jQuery实现文本域内提示文字,当鼠标点击进文本域后自动消失,文本域失去鼠标焦点后显示提示文字或显示用户输入的文字。
- js+css实现禁止鼠标右键与选中网页文字
- js实现点击图片将图片地址复制到粘贴板的方法
- OpenCV学习笔记1:使用Camera获取图像,并用Canny转换成边缘图,并支持鼠标点击保存图片
- Textview增加图片并实现点击与文字设置不同大小颜色
- unity_NGUI_实现点击鼠标左键切换给定图集中的图片显示
- js点击后将文字复制到剪贴板,将图片复制到画图
- JS实现鼠标分别点击如"上海"、"北京"、"天津" 文字,下拉框 就selected 对应的城市
- jquery实现点击文字可编辑并修改保存至数据库
- [置顶] Android 实现WebView点击图片查看大图列表及图片保存