初学AS3的几点技巧汇总

所属分类: 媒体动画 / Flash教程 阅读数: 360
收藏 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
更多精彩内容其他人还在看

Flash AS 入门 为“关键帧”添加动作

这篇文章主要是介绍flash as编程中,为关键帧添加动作的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Flash AS 入门 为“按钮”添加鼠标事件

这一节将学习为按钮添加鼠标事件来控制动画的播放状态和控制影片剪辑的播放,实现简单的交互
收藏 0 赞 0 分享

Flash AS 入门 为“影片剪辑”添加鼠标事件

这一节将用上一节学习过的语句,在影片剪辑上添加动作来控制主场景时间轴以及影片剪辑自身的播放
收藏 0 赞 0 分享

Flash AS 入门 “影片剪辑”属性调整及路径解析

本节应掌握的知识要点①影片剪辑属性调整;②相对路径、绝对路径的应用;③赋值运算符“=”应用;④了解算术组合赋值运算符“+=”、“-=”、“*=”、“/=”。
收藏 0 赞 0 分享

Flash AS 入门 条件判断语句 if、else使用介绍

条件判断语句在flash中是实用性很强、使用也很频繁的语句,这一节将学习条件判断语句“if、else”以及“trace”语句的应用
收藏 0 赞 0 分享

Flash AS 入门 duplicateMovieClip和removeMovieClip应用

本节应掌握的知识要点①duplicateMovieClip和removeMovieClip应用;②_visible属性应用;③数组应用
收藏 0 赞 0 分享

Flash AS 入门 “for”循环语句应用

本节应掌握的知识要点①for循环应用;②nextFrame()、prevFrame()动作应用;③层深度的进一步理解
收藏 0 赞 0 分享

Flash AS 入门 鼠标跟随的应用实现

本节应掌握的知识要点① startDrag和stopDrag应用;②with 语句应用
收藏 0 赞 0 分享

Flash AS 入门 onClipEvent()事件处理函数

本节应掌握的知识要点① onClipEvent()应用;②_xmouse 属性;③int函数应用
收藏 0 赞 0 分享

Flash AS 实例进阶 循环按钮

按钮触发事件发生后有可执行的两个以上的命令。②由条件判断语句来执行不同的命令。③按钮的外观要有相应的切换(如果需要)
收藏 0 赞 0 分享
查看更多