月度存档: 11 月 2012
flash获取外部div宽高
as3滤镜效果
(1)斜角滤镜(BevelFilter)
对应AS代码:
[code]
var bevel:BevelFilter = new BevelFilter();
bevel.blurX = 15;
bevel.blurY = 15;
bevel.strength = 2;
bevel.quality = BitmapFilterQuality.LOW;
bevel.shadowColor = 0x000000;
bevel.shadowAlpha = 1;
bevel.highlightColor = 0xFFFFFF;
bevel.highlightAlpha = 1;
bevel.angle = 45;
bevel.distance = 5;
bevel.knockout = false;
bevel.type = BitmapFilterType.INNER;
var filtersArray:Array = new Array(bevel);
tt.filters = filtersArray;
[/code]
(2)模糊滤镜(BlurFilter)
对应AS代码:
[code]
var blur:BlurFilter = new BlurFilter();
blur.blurX = 2;
blur.blurY = 2;
blur.quality = BitmapFilterQuality.LOW;
var filtersArray:Array = new Array(blur);
tt.filters = filtersArray;
[/code]
(3)投影滤镜(DropShadowFilter)
对应AS代码:
[code]
var shadow:DropShadowFilter = new DropShadowFilter();
shadow.blurX = 10;
shadow.blurY = 10;
shadow.strength = 1.5;
shadow.quality = BitmapFilterQuality.MEDIUM;
shadow.color = 0x000000;
shadow.alpha = 1;
shadow.angle = 45;
shadow.distance = 5;
shadow.knockout = false;
shadow.inner = false;
shadow.hideObject = false;
var filtersArray:Array = new Array(shadow);
tt.filters = filtersArray;
[/code]
(4)发光滤镜(GlowFilter)
对应AS代码:
[code]
var glow:GlowFilter = new GlowFilter();
glow.blurX = 20;
glow.blurY = 20;
glow.strength = 1.5;
glow.quality = BitmapFilterQuality.MEDIUM;
glow.color = 0x00ff00;
glow.alpha = 1;
glow.knockout = false;
glow.inner = true;
var filtersArray:Array = new Array(glow);
tt.filters = filtersArray;
[/code]
flash加载路径问题
主flash加载分flash的时候,如果程序里面写的是相对路径,本地测试没有问题
放到网上去的时候会去取域名下的flash文件,但是一般flash文件是放在某个映射的外部目录下,所以会取不到,这种情况下,就应该加上base参数
下面是引用flash的方法:
[code]
[/code]
flash as2/as3 向后台传参数url编码 urlencode(解决中文传参乱码问题)
flash as2中:
getURL(“input.aspx?type=”+ “中文”, “_blank”);
这样的做法时常会遇到后台无法正确解析这里所谓字符串“中文”现象,而用escape()将参数转成url编码的格式,问题就解决了
getURL(“input.aspx?type=”+escape(”中文”), “_blank”);
flash as3中:
用encodeURI()
flash AS3中的urlencode函数与javascript中的ulrencode函数是一样的,分别是escape、encodeURI、encodeURIComponent三个函数。我们看下面一段例子:
ActionScript 3:
var a:String = “超越梦想#”;
trace(escape(a)); //%u8D85%u8D8A%u68A6%u60F3%23
trace(encodeURI(a)); //%E8%B6%85%E8%B6%8A%E6%A2%A6%E6%83%B3#
trace(encodeURIComponent(a)); //%E8%B6%85%E8%B6%8A%E6%A2%A6%E6%83%B3%23
JavaScript:
var a = “超越梦想#”;
alert(escape(a)); //%u8D85%u8D8A%u68A6%u60F3%23
alert(encodeURI(a)); //%E8%B6%85%E8%B6%8A%E6%A2%A6%E6%83%B3#
alert(encodeURIComponent(a)); //%E8%B6%85%E8%B6%8A%E6%A2%A6%E6%83%B3%23
三个函数的的区别也和javascript的一样,一般情况下如果你把这段字符串当作参数传输就用encodeURIComponent,如果你只是把一个URL中的非字母数字等字符转化成%的形式,就用encodeURI,他们的区别就在于对于URL中的特殊字符例如 # 和 / 理解不同, 前者会转化掉,后者会认为这是url的一部分,保留原有形式。
下面列举AS3中三个函数的具体说明:
escape:
将参数转换为字符串,并以 URL 编码格式对其进行编码,在这种格式中,大多数非字母数字的字符都替换为 % 十六进制序列。 当用于 URL 编码的字符串时,百分号 (%) 用于引入转义字符,不与模运算符 (%) 等效。
下表显示不会 由 escape() 函数转换为转义序列的所有字符。
未编码的字符
0 1 2 3 4 5 6 7 8 9
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
@ – _ . * + /
参数 str:String — 要转换为字符串并以 URL 编码格式进行编码的表达式。
返回 String — 一个 URL 编码的字符串。
encodeURI:
将字符串编码为有效的 URI(统一资源标识符)。 将完整的 URI 转换为一个字符串,其中除属于一小组基本字符的字符外,其它所有字符都编码为 UTF-8 转义序列。
下表显示不会由encodeURI函数转换为 UTF-8 转义序列的基本字符的整个集合。
未编码的字符
0 1 2 3 4 5 6 7 8 9
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
; / ? : @ & = + $ , #
– _ . ! ~ * ( ) 还有单引号
参数
uri:String— 一个表示完整 URI 的字符串。
返回
String— 一个字符串,其中某些字符已编码为 UTF-8 转义序列。
encodeURIComponent:
将字符串编码为有效的 URI 组件。 将 URI 的子字符串转换为以下字符串:除属于非常小的一组基本字符的字符外,其它所有字符都编码为 UTF-8 转义序列。
encodeURIComponent()函数与encodeURI()函数不同,它仅适用于 URI 字符串的一部分(称为 URI 组件)。 URI 组件是指出现在某些特殊字符之间的任何文本,这些特殊字符称为组件分隔符(: / ; and ?). “http”和“www.adobe.com”是常见的 URI 组件示例。
此函数与encodeURI()的另一个重要区别是:由于此函数假定它处理的是 URI 组件,因此它会将特殊分隔符字符 (; / ? : @ & = + $ , #) 视为应进行编码的常规文本。
下表显示不会由encodeURIComponent函数转换为 UTF-8 转义序列的所有字符。
未编码的字符
0 1 2 3 4 5 6 7 8 9
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
– _ . ! ~ * ( ) 还有单引号
参数
uri:String
返回
String
AS3中的encodeURI,encodeURIComponent,decodeURI以及decodeURIComponent
在ActionScript 3中,除了escape和unescape两个字符串编码和解码函数以外,新增了encodeURI,encodeURIComponent,decodeURI,decodeURIComponent四个函数
(一)、如果你在实际项目AS2中用的是escape,而在js中用了unescape,却始终得不到原始的值, 那么原因就是在AS2中,没有与js的escape对应的函数,而AS2中的escape,实现的却是其他语言中的encodeURI或URIEncode的功能,AS3中,终于把escape和encodeURI区分开来了,AS3中的encodeURI和decodeURI与AS2中的escape和unescape大体相似,但要要根据具体未编码字符而定。例如:
在as2中:
trace(escape(“超越梦想#”)); //输出:%E8%B6%85%E8%B6%8A%E6%A2%A6%E6%83%B3%23
在as3中:
trace(encodeURI(“超越梦想#”)); //输出:%E8%B6%85%E8%B6%8A%E6%A2%A6%E6%83%B3#
trace(encodeURIComponent(“超越梦想#”)); //输出:%E8%B6%85%E8%B6%8A%E6%A2%A6%E6%83%B3%23
(二)、AS3中的encodeURI和decodeURI与AS2中escape和unescape不一样的地方:
在AS2中,System.useCodepage影响escape对双字节字符编码和解码的结果,注意下面System.useCodepage设为true和false的时候,输出是不同的:
System.useCodepage=true;
trace(escape(“超越梦想#”)); //输出:%B3%AC%D4%BD%C3%CE%CF%EB%23
System.useCodepage=false;
trace(escape(“超越梦想#”)); //输出:%E8%B6%85%E8%B6%8A%E6%A2%A6%E6%83%B3%23
在AS3中,System.useCodepage不影响decodeURI的结果,两个结果是一样的:
System.useCodePage = true;
trace(encodeURI(“超越梦想#”)); //输出:%E8%B6%85%E8%B6%8A%E6%A2%A6%E6%83%B3#
System.useCodePage = false;
trace(encodeURI(“超越梦想#”)); //输出:%E8%B6%85%E8%B6%8A%E6%A2%A6%E6%83%B3#
在AS3中,escape同样也不受System.useCodePage的影响:
System.useCodePage = true;
trace(escape(“超越梦想#”)); //输出:%u8D85%u8D8A%u68A6%u60F3%23
System.useCodePage = false;
trace(escape(“超越梦想#”)); //输出:%u8D85%u8D8A%u68A6%u60F3%23
这说明在AS3中,所有运用到escape和encodeURI的地方,都不能再通过设置System.useCodePage来改变编解码的方式,与后台或其他程序语言交互就必须考虑这个问题,以后后台编码的时候,记得要以UTF-8编码,否则decodeURI就会抛出URIError,提示无效的URI;
As2和As3的右键菜单
As2:
[code]
var _amyflash = new ContextMenu();
//删除原始菜单状态!
_amyflash .hideBuiltInItems();
//自定义菜单项目!
_amyflash .customItems.push(new ContextMenuItem(“copyright:amyflash”, home));
//菜单子程序执行目标…
function home() {
getURL(“;http://amyflash.duapp.com//”, “_blank”);
}
_root.menu = _amyflash;
[/code]
As3:
[code]
var myContextMenu:ContextMenu = new ContextMenu();
myContextMenu.hideBuiltInItems();
//声明菜单新项
var item:ContextMenuItem = new ContextMenuItem(“@author amyflash”);
//添加到菜单显示项目数组
myContextMenu.customItems.push (item);
root.contextMenu = myContextMenu;
//点击按钮引发该事件
item.addEventListener (ContextMenuEvent.MENU_ITEM_SELECT ,mouseRelease);
function mouseRelease (event:ContextMenuEvent):void
{
navigateToURL(new URLRequest(“http://amyflash.duapp.com/”));
}
[/code]
as1,as2,as3全屏
//as3:
stage.displayState=StageDisplayState.FULL_SCREEN;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//as1,as2:
fscommand(“fullscreen”, “true”);
Flash获取当前文件名
As3版本:
[source]//当前文件的完整路径
var fileUrl:String = this.loaderInfo.url;
//查找路径的最后一个”/”
var flag:int = fileUrl.lastIndexOf(“/”);
//截取文件名
var fileName:String = fileUrl.substr(flag + 1, fileUrl.length);
//输出
trace(fileName);
if (ExternalInterface.available) {
ExternalInterface.call(‘alert’,swfurl);
}
[/source]
As2版本:
[source]var swf1 = _root._url.lastIndexOf(“/”)+1;
var swfurl = _root._url.substr(swf1, _root._url.length);
if (ExternalInterface.available) {
ExternalInterface.call(‘alert’,swfurl);
}
trace(swfurl);[/source]
as3对象排序
[source]
package
{
import flash.display.Sprite;
public class Main extends Sprite
{
var vegetables:Array = new Array();
public function Main() {
vegetables.push(new Vegetable(“lettuce”, 1.49));
vegetables.push(new Vegetable(“spinach”, 1.89));
vegetables.push(new Vegetable(“asparagus”, 3.99));
vegetables.push(new Vegetable(“celery”, 1.29));
vegetables.push(new Vegetable(“squash”, 1.44));
trace(vegetables);
// lettuce:1.49, spinach:1.89, asparagus:3.99, celery:1.29, squash:1.44
vegetables.sort(sortOnPrice);
trace(vegetables);
// celery:1.29, squash:1.44, lettuce:1.49, spinach:1.89, asparagus:3.99
}
private function sortOnPrice(a:Vegetable, b:Vegetable):Number {
var aPrice:Number = a.getPrice();
var bPrice:Number = b.getPrice();
if(aPrice > bPrice) {
return 1;
} else if(aPrice < bPrice) {
return -1;
} else {
//aPrice == bPrice
return 0;
}
}
}
}
class Vegetable {
private var name:String;
private var price:Number;
public function Vegetable(name:String, price:Number) {
this.name = name;
this.price = price;
}
public function getPrice():Number {
return price;
}
public function toString():String {
return " " + name + ":" + price;
}
}
[/source]
开源flash报表集合
1.Ofc(open flash chart)-
flash版本地址:http://openflashchart.com/
html5版本地址:
http://www.jangaroo.net/files/examples/flash/open-flash-chart/data-files/joo.html
2.Finger chart
3.ficharts
4.beecharts