Flash 8新特性开发实例教程

王朝other·作者佚名  2006-11-24
宽屏版  字体: |||超大  

flash 8 新特性的 API

看看上图,flash8特性的API主要集中在下面4块

1 图形效果

[Filters]多种和滤镜有关的类,可以将阴影,模糊这些特效

加到你的 mc上。

[Geometry Classes]提供了 Matrix, Point, Rectangle and ColorTransforms 等各种颜色变换效果

[MovieClip Extensions ]除了可以让mc可以利用Filter,

geometry外。还提供了 [Blending Modes]。可以让mc的每一个

点的颜色都和背景相融合,这样可以增加很多效果。[Bitmap

Caching ]可以让一个mc [cacheAsBitmap].作为位图的cache,

不用每次都进行矢量计算,提高了 performance.

[Bitmap Display ]提供了对位图精确到像素的访问能力

2 文字效果:

[TextField Extensions ],flash中原有的TextField

增加了filter[滤镜]还可以定义sharpness,thickness 。

[Text Renderer Control ] ,文字 呈现方式,比如

AntiAliasType,ColorType,GridFitType.

3 文件:

[FileReference]:用于文件上传和下载

4 外部接口

[ExternalInterface]: 用于flash和javascript

xml,的交互。

主要类如下:

BitmapData

BitmapData. Channel

Button

ExternalInterface

FileReference

FileReferenceList

Filters

BevelFilter

BitmapFilter

BitmapFilter. Quality

BitmapFilter.Type

BlurFilter

ColorMatrixFilter

ConvolutionFilter

DisplacementMapFilter

DropShadowFilter

GlowFilter

GradientBevelFilter

GradientGlowFilter

Mode

Geom

ColorTransform

Matrix

Point

Rectangle

Transform

MovieClip

MovieClip. BlendModeType

Text

TextRenderer

TextRenderer. AntiAliasType

TextRenderer. ColorType

TextRenderer. FontStyle

TextRenderer. GridFitType

TextField

这里为了最快的速度上手。只是用 mtasc 和写字本。

方法如下:

1 在http://www.mtasc.org/ 下载 mtasc,解压缩到 d:/mtasc/ [随便什么目录都成]

2 将d:/mtasc/ 加入classpath.

3 在 d:/mtasc/新建 Sonny.as,代码如下:

class Sonny {

function Sonny() {

var sonny_mc:MovieClip = _root.createEmptyMovieClip("sonny", _root.getNextHighestDepth());

sonny_mc._x = sonny_mc._y=100;

sonny_mc.beginFill(0xff6633, 100);

sonny_mc.moveTo(0, 0);

sonny_mc.lineTo(100, 0);

sonny_mc.lineTo(100, 100);

sonny_mc.lineTo(0, 100);

sonny_mc.lineTo(0, 0);

var BlurTest = new flash.filters.BlurFilter();

BlurTest.clone = true;

BlurTest.blurX = 20;

BlurTest.blurY = 20;

sonny_mc.filters = [BlurTest];

}

static function main() {

var tmp = new Sonny();

}

}

代码解释:

首先新建了一个Sonny_mc,然后在中间画了一个橙色的正方形。

然后通过BlurFilter 加了一个blur的效果在正方形上

4 新建 sonny.bat

mtasc -header 300:300:25 -main -version 8 Sonny.as -swf Sonny.swf

pause

双击sonny.bat。 则可看到Sonny.swf

则可以看到边缘很好的 模糊效果 如下:

环境: windows系统,flash mx2004 中文版

1 进入C:\Documents and Settings\your name \Local Settings\Application Data\Macromedia\Flash MX 2004\zh_cn\Configuration\Publish Profiles

注意,这里的your name是你windows系统的用户名。

将 default.xml copy一份。命名为flash8.xml.将

第2行的 <flash_profile version="1.0" name="默认文件">

默认文件 改成flash8

64行 <Version>7</Version> ,中的7改成8

2 重新启动flash8 。在 发布设置,点击当前配置 后面的导入按钮

,倒入flash8.xml 。点击下方的确定。如图所示:

好。马上做一个测试:

新建fla,在flash帧上加入如下代码:

// create textfield

this.createTextField("txtField", this.getNextHighestDepth(), 10, 10, 300, 100);

txtField.html = true;

txtField.htmlText = "<font size=60>http://www.study-i.com";’ target=_blank>http://www.study-i.com</font>";

txtField.textColor = 0x0055CC;

txtField.antiAliasType = flash.text.TextRenderer.AntiAliasType.ADVANCED;

var dropShadow = new flash.filters.DropShadowFilter();

dropShadow.blurX = 5;

dropShadow.blurY = 5;

dropShadow.distance = 3;

dropShadow.angle = 35;

dropShadow.quality = 2;

dropShadow.alpha = 0.5;

txtField.filters = [dropShadow];

发布。注意。要在IE中看。因为一般只更新IE中的player。

如果字下面出现了明显的阴影.则成功了.结果如下图所示:

下面我们看个例子:

有如下3张图片:

gif图片如下:

png图片如下

jpg图片如下:

在flash8中,我们可以将他们load进flash

新建一个fla,加入如下as代码:

Stage.scaleMode = "noScale";

urls = ["progressive.jpg", "test2.png", "test1.gif"];

var i = 0;

while (i < 3) {

var cl = this.createEmptyMovieClip("test" + i, i + 1);

cl.createEmptyMovieClip("holder", 1);

cl.holder.loadMovie(urls[i]);

cl.onPress = function () {

this.startDrag();

};

cl.onRelease = function () {

this.stopDrag();

};

i++;

}

最终的结果如下:

看看ExternalInterface类的主要方法。可以看出,ExternalInterface类主要是用于和xml,还有javascript进行交互的。

_arrayToXML

_argumentsToXML

_objectToXML

_toXML

_objectToAS

_arrayToAS

_argumentsToAS

_toAS

_arrayToJS

_objectToJS

_toJS

JavaScript to Flash

ActionScript

导入flash.external.ExternalInterface;

class ExternalInterfaceTest { public function ExternalInterfaceTest() { //第一个参数是暴露给javascript的function名 //第二个参数是真实调用的 ExternalInterface.addCallback("actionScriptFunction", actionScriptFunction); } public function actionScriptFunction(input:String):String { trace(input); return input; } }HTML / JavaScript

<SCRIPT LANGUAGE="JavaScript">

//flashId, 是网页中flash的id名

var flash = (navigator.appName.indexOf ("Microsoft") !=-1)?window["flashId"]:document["flashId"];

flash.actionScriptFunction("Hello World.");

</script>

Flash to JavaScript

在 HTML页面:

<script language="JavaScript">

function myJavaScriptFunction(input)

{

window.alert(input);

}

</script>

ActionScript

导入flash.external.ExternalInterface;

class ExternalInterfaceTest

{

public function ExternalInterfaceTest()

{

if(ExternalInterface.available)

{

ExternalInterface.call("myJavaScriptFunction", "Hello World");

}

}

}

可以参考下面文档:

http://livedocs.macromedia.com/central/sdk/1_5/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Central_SDK&file=00000275.htm

FileReference最主要的方法有2个:

最主要的方法有2个,browse(),

用于 点击后弹出文件选择框

upload();如果你上传的服务器脚本是sonny.jsp。

上传则可以写成

upload("sonny.jsp","POST");upload常见事件如下:

onUploadStart:开始上传

onUploadProgress上传进度

onUploadSuccess上传成功

onUploadFailed上传失败

好,下面举个例子。因为没有服务器的支持。主要介绍browse一段。

新建fla,然后在root上建立一个sonny_mc和一个sonny_txt [动态文本]

将下面脚本放入帧上:

var fileRef = (new flash.net.FileReference());

sonny_mc.onRelease = function () {

if (fileRef.browse()) {

sonny_txt.text = "File Name:" + fileRef.name;

}

};

发布一下。在浏览器中看看效果。

一般来说,使用filter类分为3个步骤。

1设置filter对象

2 定义filter的各个参数

3将需要效果的mc的filters属性设置为由filter对象组成的Array.如下所示:

var myfilter = new flash.filters.DropShadowFilter();

// customize the filter through public properties

mc.filters = [myfilter];

下面演示一个经典的例子。显示了模糊,阴影,外辉,内辉四种效果(// Blur,// Shado

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有