DFdou's Blog Life is short,Be yourself.

1607/090

AS2-System.capabilities

先来个Demo看下System.capabilities到底是干嘛用的:

2406/090

Flash-Adobe’s Flash to ship on new Android phone

The HTC Hero phone will have Flash support built in.(Credit: HTC)

Learned from http://news.cnet.com/8301-1035_3-10272261-94.html?part=rss&subj=news&tag=2547-1_3-0-20.

Marking a departure from the world of iPhone, HTC's new Android-based Hero phone will also come with the ability to handle Flash elements that adorn many Web sites and power YouTube video.

HTC新款Android系统手机Hero将内建Adobe Flash播放器。

Adobe Systems announced on Wednesday that its Flash Player will be built into the HTC phone, an important step in the company's efforts to spread Flash to mobile phones. The phone, one of several from HTC to use Google's open-source operating system, is scheduled to ship in Europe starting in July and in Asia and North America later in the year.

Adobe在周三发布了一个公告称Flash Player将内建在HTC手机中,这是Flash迈向手机平台关键性的一步。Hero是HTC使用Google的开源操作系统的其中一款手机,将在7月登录欧洲,并在晚些时候登录亚洲和北美。

1806/090

Flash-Transparent时在FF和Safari下无法输入中文的解决方案

Learned from 《swfInputs: Solving Mozilla + Transparent Mode + Win + Special Chars within inputs》
原来写过个日志《Flash在Safari下无法输入中文》,当时没有找到好的解决方案,现在在网上看到有这么个东西,swfInputs
What to do in your code?具体代码的使用:
swfInputs consists of two parts(swfInputs包含2个部分):
* The SWFTextInput AS3 Class (which create the connection to the JavaScript class),一个AS3组件,负责Flash和JS的通信。
* and the swfInputs JavaScript Class (which handles the creation and HTML communication),一个JS文件,负责在HTML端建立Input。
To activate the JavaScript part you just need to insert two script-tags into the HTML code and call the constructor method. At the moment swfInputs uses the dojoToolkit JavaScript library for position calculation and basic connection handling. I looking forward to remove this need of dojo to reduce the filesize.
swfInputs使用dojoToolkit JS框架,恩,作者根据需求修正了dojoToolkit的尺寸。

<script src="../javascript/dojo.js" language="javascript"></script>
<script src="../javascript/swfInputs.js" language="javascript"></script>
<script language="JavaScript" type="text/javascript">
			swfInputs.init('swfInputTestcase');
</script>
2805/090

AAS3WDP-Chapter 8 Composite 组合模式(下)

接上集《AAS3WDP-Chapter 8 Composite 组合模式(上)》,上集讲到了建立叶子元素和组合元素,这集先讲xml文件:

< ?xml version="1.0" encoding="utf-8"?>
<filesystem>
	<filesystemitem type="Directory" name="Program Files" bytes="1024">
		</filesystemitem><filesystemitem type="Directory" name="Adobe Flash">
			<filesystemitem type="File" name="Flash.exe"/>
			<filesystemitem type="File" name="Hello.txt"/>
			<filesystemitem type="File" name="Today.txt"/>
		</filesystemitem>

	<filesystemitem type="Directory" name="Other" bytes="1024">
		<filesystemitem type="File" name="Hello.txt"/>
		<filesystemitem type="File" name="Image.jpg"/>
	</filesystemitem>
</filesystem>

xml里,文件分2个目录,Program Files和Other,Program Files目录下有子目录Adobe Flash,子目录Adobe Flash中有3个文件,而Other下有2个子文件,下边我们就用这个xml来模拟一个文件结构目录。

2705/090

AAS3WDP-Chapter 8 Composite 组合模式(上)

啊,这一贴比较麻烦,内容也比较多,所以准备分上下部分来完成。
那么,什么是组合模式呢?
组合模式是将对象之间的关系以数据结构中的2叉树表现出来,使得客户端将单纯的元素与复杂元素同等看待,这样的话使得用户在操作不同的子类元素时可以和根节点元素一样操作,在透明模式下即根元素和叶元素公用同一个接口达到共同的结果。组合模式就是解决部分与整体的关系的一种模式。
这一章是以文件系统为例,文件分为"文件夹"和"文件"两种,恩,就是这样。那么我们先来建立一个共用接口IFileSystemItem:

package{
	import IIterator;//PS:第7章的类
	public interface IFileSystemItem{
		function iterator():IIterator;
		function addItem(item:IFileSystemItem):void;
		function removeItem(item:IFileSystemItem):void;
		function getName():String;
		function setName(name:String):void;
		function getParent():IFileSystemItem;
		function setParent(parent:IFileSystemItem):void;
	}
}
2205/090

About Flash

今天在CSDN看到个题为《Adobe宣布Flex Builder将更名为Flash Builder》的东西,这个怎么说呢,什么是Flex,然后,什么是Flash?
其实一开始推出个Flex估计Adobe是想让她和Flash区分开来,而后来呢,Flash的定义被更改了,,于是现在又绕了回来,改成了Flash Builder~不过SDK依然是叫Flex SDK哈哈…纠结吧?ORZ。
那到底Flash是什么东西呢?如果你的想法还停留在Flash动画的年代,那赶紧更新下,不然就OUT了,,。
想看详细信息的可以点此下载官方的PDF《ADOBE® FLASH® 平台》

1905/090

AAS3WDP-Chapter 7 Iterator 迭代模式

什么是迭代器模式?迭代器模式是干嘛的呢?
迭代器(Iterator)模式,又叫做游标(Cursor)模式。GOF给出的定义为:提供一种方法访问一个容器(container)对象中各个元素,而又不需暴露该对象的内部细节。
这一章的例子是创建一个存储uint类型的UIntCollection类,关系到4个文件,先是ICollection接口。
该接口只有一个方法,而该方法返回迭代器接口IIterator,参数type用于判断返回哪种类型的迭代器。

package{
	public interface ICollection{
		function iterator(type:String=null):IIterator;
		//other
	}
}

接着是IIterator接口,该接口定义了3个方法。

package{
	public interface IIterator{
		function reset():void;
		function next():Object;
		function hasNext():Boolean;
		//other
	}
}
1505/090

AAS3WDP-Chapter 6 Remote Proxy 远程代理

这里是一个Flickr的远程图片搜索代理实例,对了,Flickr的远程图片搜索需要申请API,别忘了去申请一个。
代码部分,类PhotoSearchProxy.as:

package{
	import flash.events.DataEvent;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class PhotoSearchProxy extends EventDispatcher{
		private static const API_KEY:String="c4643072bfc38caa0257f4c039624cb5";//这是我的Flickr Api_key
		private static const FLICKR_URL:String="http://api.flickr.com/services/rest/";//Flickr的api地址

		public function PhotoSearchProxy(){}
		private function onComplete(_evt:Event):void{
			dispatchEvent(new DataEvent(Event.COMPLETE,false,false,XML(_evt.target.data)));
		}
		public function search(userId:String,tags:String):void{
			var loader:URLLoader=new URLLoader();
			var request:URLRequest=new URLRequest(PhotoSearchProxy.FLICKR_URL+"?method=flickr.photos.search&user_id="+userId+"&tags="+tags+"&api_key="+PhotoSearchProxy.API_KEY);
			loader.addEventListener(Event.COMPLETE,onComplete);
			loader.load(request);
		}
	}
}

在loader载入request之后dispatchEvent一个DataEvent。
具体调用部分:

import PhotoSearchProxy;
var flickr:PhotoSearchProxy=new PhotoSearchProxy();
flickr.addEventListener(Event.COMPLETE,onComplete);
flickr.search("","yellow");
function onComplete(_evt:DataEvent){
	trace(_evt.data);
}

实际化PhotoSearchProxy之后,调用search方法,load完之后接收dispatchEvent的DataEvent的data并trace。
记得以前看过的一个AIR的RSS阅读器也是这样做的,写了个EventDispatcher的子类,载入RSS源地址后dispatchEvent。。。

1405/090

AAS3WDP-Chapter 6 Virtual Proxy 虚拟代理模式

按照习惯应该先鬼扯下什么是Virtual Proxy,……话说…还是直接参阅Java设计模式的Virtual Proxy吧,或者看看这个吧:"Java设计模式之虚拟代理模式"
Flash里边的Loader就是一个代理,书上的说法是这样的,本来一个元件是必须等到加载完成才能加载到显示列表中的,但是用了虚拟代理之后,可以将代理当成一个加载完成后的元件,加入到显示列表中。
下边么,来点代码,先是接口类IProduct.as:

package{
	public interface IProduct{
		//get method
		function getPrice():Number;
		function getTitle():String;
		//set method
		function setPrice(price:Number):void;
		function setTitle(title:String):void;
	}
}
1305/090

AAS3WDP-Chapter 5 Factory 工厂模式

接这上次的"AAS3WDP-Chapter 5 Template Method模板方法",现在是工厂模式。
先来AbstractGameEXP类,相比之下,在模板方法里使用了var field:IField = createField();然后在子类中实现接口很方法。

package {
	import IField;
	public class AbstractGameEXP {
		public function initialize():void {
			var field:IField = createField();
			field.drawField();
			createTeam("red");
			createTeam("blue");
			startGame();
		}
		public function createField():IField {
			throw new Error("Abstract Method!");
		}
		public function createTeam(name:String):void {
			throw new Error("Abstract Method!");
		}
		public function startGame():void {
			throw new Error("Abstract Method!");
		}
	}
}
804/090

AS2-MC的循环滚动实现

Demo:


Source Code:

var startY:Number = 110;//起始y位置
var speed:Number = 0.5;//滚动速度
var mcHeight:Number = 88.5;//mc的高度
initItemMove (startY, speed, mcHeight);
function initItemMove (startY:Number, speed:Number, mcHeight:Number) {
	mc1.onEnterFrame = function () {
		this._y -= speed;
		if (this._y < startY - mcHeight - 10) {
			this._y = mc2._y + mcHeight;
		}
	};
	mc2.onEnterFrame = function () {
		this._y -= speed;
		if (this._y < startY - mcHeight - 10) {
			this._y = mc1._y + mcHeight;
		}
	};
}

循环滚动的原理很简单,就是生成2份一样的东西,例子里为mc1和mc2,然后并接排列一起往上移动,在mc1上移一定距离后(例子里为startY - mcHeight - 10),就让mc1移动到mc2的底部,如此循环,就可以实现mc的循环滚动了。
Flash中灰色部分是遮罩,为了方便看效果,左边的没做遮罩,右边的做了遮罩。

Tagged as: , No Comments
704/090

AS2-StarRate

Demo:


Source Code:

import gs.TweenLite;
var STARNUM:Number = 26;
//星总数
var STARWIDTH:Number = 20;
//星宽度
var starRateNum:Number = 10;
//默认星数
initStars ();
function initStars () {
	this.createEmptyMovieClip ("mc_star", 0);
	mc_star.createEmptyMovieClip ("mc_starG", 1);
	mc_star.createEmptyMovieClip ("mc_starL", 2);
	attachMovie ("hitArea", "starMask", 3);
	mc_star._x = mc_star._y = 15;
	starMask._x = mc_star._x;
	starMask._y = mc_star._y;
	starMask._width = starRateNum * STARWIDTH;
	mc_star.mc_starL.setMask (starMask);
	for (var i:Number = 0; i < STARNUM; i++) {
		//灰色星mc
		mc_star.mc_starG.attachMovie ("starG", "starG" + i, 10 + i);
		//高亮星mc
		mc_star.createEmptyMovieClip ("mc_starL", 2);
		mc_star.mc_starG["starG" + i]._x = mc_star.mc_starL["starL" + i]._x = STARWIDTH * i;
		mc_star.mc_starG["starG" + i].onRelease = function () {
			var btnName = this._name.substr (5);
			trace (btnName);
			btnName = int (btnName) + 1;
			trace (btnName);
			TweenLite.to (starMask, 0.3, {_width:STARWIDTH * btnName});
		};
	}
}
Tagged as: , , No Comments
403/093

AS2-setInterval and setTimeout

来自Flash8的帮助文档:
setInterval(functionReference:Function, interval:Number, [param1:Object, param2, ..., paramN]) : Number
setInterval(objectReference:Object, methodName:String, interval:Number, [param1:Object, param2, ..., paramN]) : Number
用法示例:

class CustomClass {
 private var intervalId:Number;
 private var count:Number = 0;
 private var maxCount:Number = 10;
 private var duration:Number = 20;

 public function CustomClass():Void {
 beginInterval();
 }

 private function beginInterval():Void {
 if(intervalId != null) {
 trace("clearInterval");
 clearInterval(intervalId);
 }
 intervalId = setInterval(this, "executeCallback", duration);
 }

 public function executeCallback():Void {
 trace("executeCallback intervalId: " + intervalId + " count: " + count);
 if(count >= maxCount) {
 clearInterval(intervalId);
 }
 count++;
 }
}
在新文档中,实例化新类的一个新实例:
var custom:CustomClass = new CustomClass();

setTimeout的用法和setInterval一样,只不过只执行一次,另,Flash8帮助文档中并未提及setTimeout函数……

2302/090

Flash-AS2和AS3的加载

在AS2里,加载图片和swf,使用loadMovie/loadMovieNum或者loadClip方法即可,如:

function initList (_mc:MovieClip, numStart:Number, numEnd:Number) {
	for (var i:Number = numStart; i < numEnd; i++) {
		_mc.createEmptyMovieClip ("e_avatar" + i, 1000 + (numEnd - i));
		_mc["e_avatar" + i].createEmptyMovieClip ("loader", 1000 + i);
                _mc["e_avatar" + i].loader.loadMovie(i+".jpg");
                _mc["e_avatar" + i]._x=Math.random()*stageW;//随机摆放
                _mc["e_avatar" + i]._y=Math.random()*stageH;
	}
}

相对AS2而言,AS3更加规范,加载方法统一成了load方法,例子如下:

function initList (_evt:Event):void {
	var userXML = XML(userLoader.data);
	var userNum=userXML.children().length();
	for (var i:uint=0; i<userNum; i++) {
		var e_avatarLdr:Loader = new Loader();//建立loader对象
		var e_avatarURL:String = userXML.item[i].avatar;//载入文件名称
		var e_avatarURLReq:URLRequest = new URLRequest(e_avatarURL);//建立载入接收对象
		e_avatarLdr.load (e_avatarURLReq);//使用load方法加载e_avatarURLReq
		e_avatarLdr.contentLoaderInfo.addEventListener (Event.COMPLETE, e_avatarLoaded);//载入完成后响应
		function e_avatarLoaded (_evt:Event):void {
			userAvatar.addChild (_evt.target.content);//把载入的对象加入容器
			_evt.target.content.x=Math.random()*stageW;//随机摆放
			_evt.target.content.y=Math.random()*stageH;
		}
	}
}

从例子中我们可以发现,AS2和AS3的加载机制几乎完全不同,具体内容可以参阅Flash CS3自带的帮助文档哈。

Tagged as: , , , No Comments
1902/092

AS2-Discuz!用户列表Flash效果

前天跟一朋友谈天的时候讲到一款Flash星空的效果,想了一下,准备试着把Discuz!的用户做成这种效果,努力了一下,现在差不多是可以了。
Demo:http://www.wanplus.com/userlist/
先是Flash的主要代码:

function initList (_mc:MovieClip, numStart:Number, numEnd:Number) {
	for (var i:Number = numStart; i < numEnd; i++) {
		_mc.createEmptyMovieClip ('e_avatar' + i, 1000 + (numEnd - i));
		_mc['e_avatar' + i].createEmptyMovieClip ('loader', 1000 + i);
		_mc['e_avatar' + i].createTextField ('txtUName', 1, 0, 50, 50, 50);
		loadAvatar (mcAvatar, numStart);
	}
}
//加载函数
function loadAvatar (_mc:MovieClip, num:Number) {
	_mcLoader.loadClip (xmlRoot.childNodes[num].attributes['avatar'], _mc['e_avatar' + num].loader);
	_mc['e_avatar' + num]._x = Math.random () * (stageW - 130) + 50;
	_mc['e_avatar' + num]._y = Math.random () * (stageH - 130) + 50;
	_mc['e_avatar' + num].url = xmlRoot.childNodes[num].attributes['url'];
	_mc['e_avatar' + num].onRelease = function () {
		getURL (this.url);
	};
}
Page 1 of 212