网站建设 | 建站知识 | 网站设计 | 房产财经 | 七彩商务 | 医疗保健 | 短信大全 | 动画欣赏 | 设计课堂 | 设计教程
建网站 | 站长学院 | 建站教程 | 网页教程 | 网站教程 | 推广教程 | 平面教程 | 动画教程 | 营销策划 | 广告设计
联系我们 | 服务宗旨 | 企业建站 | 网站策划 | 网站制作 | 网站宣传 | 宣传推广 | 财经频道 | 网站地图
服务中心 建立网站 建站方案 网页设计 网站建设 网站改版 网站推广 案例展示
七彩课堂
广告设计教程
程序开发教程
电脑维护教程
网页标准教程
平面设计教程
闪客动画教程
网站建设教程
网站推广教程
网页设计教程
网页制作教程
网站设计教程
dreamweaver
课堂通道
网页设计: 01 02 03 04
平面设计: 01 02 03 04
网站推广: 01 02 03 04
网站建设: 01 02 03 04
网页制作: 01 02 03 04
动画教程: 01 02 03 04
建站知识: 01 02 03 04
>>>> 查看更多
合作支持
英国留学 | 工艺品 | 商标注册 | 水疗设备 | 卓迈国际 | 打包带 | 杭州鲜花 | 搞笑短信 | 情人节鲜花 | Nike Shoes
   
七彩课堂[FLASH动画教程系列]
flash计算器的制作[上]
[学习目标]:掌握if语句的格式和功能,通过实际例子进一步的掌握变量、运送符、函数等概念,
在上个教程我给大家说说数据类型、变量、运送符、函数等几个概念,下面我再给大家介绍下if语句,然后就通过制作一个flash的计算器来更好的掌握这些概念。
有了前面大家的学习,我们可以看到as控制动画的表演都是按照时间轴的顺序,有序的播放的,as的语句都是从上至下运行的,当然我们可以让as有点人的逻辑思维,根据具体的情况判断下,再去播放。这就需要我们了解as语句的三种结构:顺序、选择、循环结构。
一、三种结构简说
对于顺序结构,很好理解,前面我们写的都是顺序的,按我们写的as语句的顺序,一行行的从上到下的执行。选择结构就是根据先判断条件,条件成立去做一系列的事情,不成立做另一系列的事情。循环就是反复去做某些事情了,要它停止下来,你必须给它停止的条件。
二、选择结构分2种类型
如果我们在创作动画时需要根据具体的情况来确定动画的播放,就要用到选择了,对as来说有2种类型的选择,一是就2种情况来选择的if语句,二是有多种情况可选择的switch语句。比如我们投硬币决定今天谁来请客,就是一 个判断,就2种情况,正面和反面,如果在饭馆我们谁点的菜就放在谁边,对菜就是多选择了。就用switch表示了。
三、如何写if语句
一般有下面3种情况:
1、最近简单的,一个选择。
if(表达式) {语句 ;\\如果表达式的值为真,就执行语句.否则什么也不做.}
2、标准格式
if(表达式){ 语句1}
else
{语句2;}\\如果表达式的值为真,就执行语句1,如果为假就执行语句2.
3、多条件嵌套
if(表达式1) {语句1;}
else if (表达式2) {语句2;}
else if (表达式3) {语句3;}
else if (表达式n) {语句n;}
else {语句 m;}
这个嵌套要注意的就是层次关系,不能套错了,在这里先理解吧。
比如上面的例子我们可以写成这样:
if ( 硬币的面的情况是正面?)
{我掏钱请你吃饭;}
else
{你掏钱请我吃了;}
下面我们就看个例子:
要求:做个简单的计算器
步骤:
1、新建flash文档。
2、在新建的图层calc_skin画个计算器的外壳样子,这个是自己的美术功底了,不画也可以的。
3、新建按扭元件Digit_btn。
4、新建图层calc_btn,从库中拖入21次按扭Digit_btn,然后按计算器的布局排好,分别在每个按扭上加个文本1、2、3、4、5、6、7、8、9、0、+、—、×、/、%、M+、MR、MC。
5、新建图层calc_txt,放入3个动态文本框,分别对应3个变量mem,display,symbol,其中,变量mem是用来显示中间计算结果存储情况的,display是用来显示输入数据和计算结果的,symbol是用来显示运算符的。
5、新建图层ActionScript,在第一关键桢加as:
// Calculator design and made by jinjun
fscommand("showmenu", false);//关闭右键菜单
fscommand("allowscale", false);//播放不进行缩放
fscommand("fullscreen", false);//不全屏幕显示
// ***Initializing the variables
display = "0";//显示输入和计算结果的变量
stop();// 取得操作数并显示的函数
function getdigit(digit) {
if (clear) {
clear = false;
decimal = false;
display = "0";
}
if (length(display)<13) {
if (display == "0" and digit != ".") {
display = digit;
} else {
display = display+digit;
}
}
}// 取得运算符并运算显示运算结果的函数
function getoperator(sign) {
if (operator == "+") {
display = Number(operand)+Number(display);
symbol = operator;
}
if (operator == "*") {
symbol = "x";
display = operand*display;
}
if (operator == "-") {
symbol = operator;
display = operand-display;
}
if (operator == "/") {
symbol = operator;
display = operand/display;
}
operator = "=";
clear = true;
symbol = " ";
decimal = "false";
if (sign != null) {
operator = sign;
if (operator == "*") {
symbol = "x";
} else {
symbol = operator;
}
operand = display;
}
}
// Calculator design and made by jinjun
fscommand("showmenu", false);//关闭右键菜单
fscommand("allowscale", false);//播放不进行缩放
fscommand("fullscreen", false);//不全屏幕显示
// ***Initializing the variables
display = "0";//显示输入和计算结果的变量
stop();// 取得操作数并显示的函数
function getdigit(digit) {
if (clear) {
clear = false;
decimal = false;
display = "0";
}
if (length(display)<13) {
if (display == "0" and digit != ".") {
display = digit;
} else {
display = display+digit;
}
}
}// 取得运算符并运算显示运算结果的函数
function getoperator(sign) {
if (operator == "+") {
display = Number(operand)+Number(display);
symbol = operator;
}
if (operator == "*") {
symbol = "x";
display = operand*display;
}
if (operator == "-") {
symbol = operator;
display = operand-display;
}
if (operator == "/") {
symbol = operator;
display = operand/display;
}
operator = "=";
clear = true;
symbol = " ";
decimal = "false";
if (sign != null) {
operator = sign;
if (operator == "*") {
symbol = "x";
} else {
symbol = operator;
}
operand = display;
}
}
// Calculator design and made by jinjun
fscommand("showmenu", false);//关闭右键菜单
fscommand("allowscale", false);//播放不进行缩放
fscommand("fullscreen", false);//不全屏幕显示
// ***Initializing the variables
display = "0";//显示输入和计算结果的变量
stop();// 取得操作数并显示的函数
function getdigit(digit) {
if (clear) {
clear = false;
decimal = false;
display = "0";
}
if (length(display)<13) {
if (display == "0" and digit != ".") {
display = digit;
} else {
display = display+digit;
}
}
}
// 取得运算符并运算显示运算结果的函数
function getoperator(sign) {
if (operator == "+") {
display = Number(operand)+Number(display);
symbol = operator;
}
if (operator == "*") {
symbol = "x";
display = operand*display;
}
if (operator == "-") {
symbol = operator;
display = operand-display;
}
if (operator == "/") {
symbol = operator;
display = operand/display;
}
operator = "=";
clear = true;
symbol = " ";
decimal = "false";
if (sign != null) {
operator = sign;
if (operator == "*") {
symbol = "x";
} else {
symbol = operator;
}
operand = display;
}
}
七彩课堂推荐教程
网页设计|网站维护|七彩社区|祝福语|毛尖茶|招聘|留言|百科|游戏|搜索|短信|家园|热点|博客|鲜花|留学
传统节日|中华民俗|生日短信|问候短信|情人短信|新年短信|新春祝福|春节短信|流行动画|MTV动画
育儿知识|家庭医生|中医治疗|加盟合作|买卖求购|供应信息|网站赚钱|赚钱技巧|买房置业|投资理财
2005 -2008© Copyright QicaiSpace.com All rights receand. [七彩空间专业建网站做网站].
热线/MOB: 13396526989  电话/TEL: 0571 -- 63136250    E-mail: art01@163.com