易截截图软件、单文件、免安装、纯绿色、仅160KB

工厂设计模式【Flash】

  工厂模式在设计模式中可以说是最简单的一个模式了!我们平常写程序的时候工厂模式用的非常的广泛!这里我们就来详细的探讨一下工厂模式。
   工厂模式是怎样诞生的呢?在实际的编程过程当中我们经常要碰到一个问题,就是类的封装,也可以说是隐藏产品类!这样我们就出现了工厂模式!这个模式就是专门用来隐藏产品类的!平常我们要是创建一个Sprite类的实例我们会这样写:
var my:Sprite = new Sprite();
addChild(my);
   这样写看似简单明了!但事实上不符合我们隐藏产品类的目的!设想一下!这样写之后,在类中任意一个方法都可以访问到这个对象,这是我们不希望的。所以,我们就要想办法隐藏这个Sprite(在实际编程的时候一般都是比较复杂的对象)类。那么我们怎么做呢?首先我们要有一个思路!就是使用“中介”(这个名字是我自己起的)。这个中介是产品类与客户中间的一座桥梁,我们通过中介来生成产品。这样就可以来隐藏产品类了!
 那么好了,我们来看一个简单的实例吧!这里我们的产品类使用的是接口!那么我们这个产品做什么呢?为了简单起见,我们的产品一个画一个正方形,另一个画一个圆形。这样来区分2个产品。
IShape接口:
package{
public interface IShape{
function moveshape(X:int,Y:int):void;
function drawshape():void;
}
}  
Round类:
package{
import flash.display.Shape;
public class Round extends Shape implements IShape{
public function drawshape():void{
graphics.beginFill(0x00ff00);
graphics.drawCircle(0,0,100);
graphics.endFill();
}
public function moveshape(X:int,Y:int):void{
this.x = X;
this.y = Y;
}
}
}  
Rectshape类:
package {
import flash.display.Shape;
public class Rectshape extends Shape implements IShape{
public function drawshape():void{
graphics.beginFill(0xff00ff);
graphics.drawRect(0,0,100,100);
graphics.endFill();
}
public function moveshape(X:int,Y:int):void{
this.x = X;
this.y = Y;
}
}
}  
DrawshapeObject类:
package{
import flash.errors.IllegalOperationError;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
public clas


相关文档:

flash 绘图API:绘制一棵树


 这个程序是从2.0 改过来的,是网上一个程序,只是修改了一些内容,变成这种情况。这几天没有写程序,有点懒惰。于是今天又补充这种不错的应用。这个程序采用的是绘图API 最基本的绘制线,但是对其进行一些修改,使他产生上面的效果。漂亮不?呵呵,我都觉几漂亮,
作为绘图API 一个内容补充吧。
好,闲话不说。看 ......

flash 之 URLLoader


var loader:URLLoader = new URLLoader();
loader.addEventListener(ProgressEvent.PROGRESS, handleProgress );
event:ProgressEvent     event.bytesLoaded/event.bytesTotal
var streamer:URLStream = new URLStream( );
streamer.addEventListener( ProgressEvent.PROGRESS, handleProgress ......

Flex——Flash Player Not Found

Are you running your Flex Application and continually getting the error below?
"Flex Builder cannot locate the required version of the Flash Player. You might need to install Flash Player 9 or reinstall Flex Builder. Do you want to try to run your application with the current version?"
Description ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号