初学AS3的几点技巧汇总

所属分类: 媒体动画 / Flash教程 阅读数: 345
收藏 0 赞 0 分享
1.null和undefined的差別在於
null是指沒有值
undefined是宣告未完全、沒有宣告這個屬性或沒有指定資料型態(未賦予值沒做過資料轉型也算)
null==undefined但null!==undefined
所以我們常常要檢查外部變數有沒有被賦予值要用
if(外部變數==null){
外部變數沒有被賦予值
}
2.把變數宣告在所有程式(FUNCTION)的最上面
3.執行container.addChild(ball_A);時,若container已存在ball_A這個物件,在執行1次的功能在於,PLAYER會把原有的ball_A刪掉,再重新加入ball_A,所以ball_A顯示的順序就會變成在最上面,若你要指定顯示順序就用container.addChildAt(ball_A, 1);這個指令(0-N),0為最底層N為目前最上面ㄧ層
4.自動管理顯示順序
trace(container.getChildAt(0).name); // ball_A
trace(container.getChildAt(1).name); // ball_C
trace(container.getChildAt(2).name); // ball_B
container.removeChild(ball_C);
trace(container.getChildAt(0).name); // ball_A
trace(container.getChildAt(1).name); // ball_B
5.delete 才會完整的把物件殺掉removeChild只是移除顯示清單而已,ㄧ個物件只能對應一個container
6.其他好用的函式
contains(): Determines whether a display object is a child of a DisplayObjectContainer.
getChildByName(): Retrieves a display object by name.
getChildIndex(): Returns the index position of a display object.
setChildIndex(): Changes the position of a child display object.
swapChildren(): Swaps the front-to-back order of two display objects.
swapChildrenAt(): Swaps the front-to-back order of two display objects, specified by their index values.
7.取代AS 2.0 用[]動態命名的方法
import flash.display.Sprite;
var container1:Sprite = new Sprite();
container1.name="allen";
container1.x=20;
var container2:Sprite = new Sprite();
container2.addChild(container1);
addChild(container2);
trace(container2.getChildByName("allen").x);
沒錯就是這一行container1.name="allen";直接指定name
更多精彩内容其他人还在看

ColorTransform类调整显示对象的颜色值

ColorTransform 首先,我们要知道,一个颜色由四个通道组成:红、绿、蓝和alpha通道(这个alpha通道在PS里我不知道对应哪个),他们的十六进制颜色值分别为: 红:0xffff0000       绿:0xff00ff0
收藏 0 赞 0 分享

Flash AS3 快速制作烟雾动画

Flash AS3教程:快速制作烟雾动画,由于还要上传AS不给大家看效果了,本文最后提供源码压缩包下载,本教程主要利用AS3的类来实现。首先我们在Photoshop中制作一个烟雾的照片,这里主要使用Photoshop的画笔来实现。 之后我们导入到FLASH中来,然后转变
收藏 0 赞 0 分享

Flash AS3 制作文字飞出动画

效果:   代码: [code] import gs.TweenMax; txtInfo.text="TextField 类用于创建显示对象以显示和输入文本。 SWF 文件中的所有动态文本字段和输ActionScript 提供了多种在运行时设置文本格式
收藏 0 赞 0 分享

Flash 制作晃动光线文字特效

看到网上有个很好的效果,自己学着做了一个,先看看效果演示
收藏 0 赞 0 分享

Flash 绘画技巧 投影滤镜设置阴影

这个例子我们将在它的结构中使用投影滤镜。这个技巧将提供一个很酷的方法,用相同的滤镜获得更多的层次和透视图。
收藏 0 赞 0 分享

ActionScript 学习小心得

ActionScript学习小得
收藏 0 赞 0 分享

ActionScript3.0读取网页FlashVars中的参数的问题

最近在做一个从网页读取参数的swf,以前用AS2.0可以直接读取FlashVars中的变量,但是AS3.0却无法取到。
收藏 0 赞 0 分享

Flash 视频广告的定位兼容性问题

在项目中,用到了一个Flash视频广告,但是该视频广告在Firefox中显示实在是差强人意,居然漂浮在了网站的左上角,该怎么解决这个问题呢?
收藏 0 赞 0 分享

flash 超链接问题

昨天我的朋友找我帮忙,想在他们网站的首页的flash上加一个超链接,点击后导向一个页面,我知道flash不支持click等事件,在网上搜索一下,发现几种方法,下面逐一说明一下,省的后续zz们走弯路
收藏 0 赞 0 分享

Flash AS 制作创意的鼠标经过的网页导航

鼠标经过-导航条出现;鼠标移开-导航条消失。
收藏 0 赞 0 分享
查看更多