一、涉及特性
本實(shí)例不太復(fù)雜,主要涉及組件的應(yīng)用、對(duì)組件的編程和對(duì)JavaScript的應(yīng)用,都是Flash MX 2004中的新特性。
二、制作過程
1、從組件欄中拖四個(gè)Numeric Stepper到場(chǎng)景中,分別設(shè)置屬性如下:A、命名為start_stp,設(shè)置Maximum為10000,設(shè)置Minimum為1,step為1,value為100;B、命名為end_stp,設(shè)置Maximum為10000,設(shè)置Minimum為0,step為1,value為100;C、命名為color_stp,設(shè)置Maximum為100,設(shè)置Minimum為0,step為1,value為100;D、命名為area_stp,設(shè)置Maximum為500,設(shè)置Minimum為0,step為1,value為10。
2、從組件欄中拖兩個(gè)Combo Box到場(chǎng)景中,分別設(shè)置屬性如下:A、命名為curve_cb,設(shè)置labels為“[normal, very tight, pixels, smooth, very smooth]”,設(shè)置rowCount為5;B、命名為corner_cb,設(shè)置labels為“[normal, many corners, few corners]”,設(shè)置rowCount為5。
3、從組件欄中拖一個(gè)Button到場(chǎng)景中,命名為submit_btn,設(shè)置Labels為Submit。然后排列所有組件如圖1所示。
4、在TimeLine中新建一個(gè)圖層,命名為Actions,在該層的Action面板中增加如下語句:
/* Copyright 2003 Macromedia, Inc. All rights reserved.
The following is Sample Code and is subject to all restrictions
on such code as contained in the End User License Agreement
accompanying this product.
*/
function click() {
var tab = " ";
var asNewLine = "\n";
//注釋1
if (start_stp.value == "") {
var startKF_as = "\"\"";
} else {
var startKF_as = start_stp.value;
}
if (end_stp.value == "") {
var endKF_as = "\"\"";
} else {
var endKF_as = end_stp.value;
}
if (color_stp.value == "") {
var threshold_as = "\"\"";
} else {
var threshold_as = color_stp.value;
}
if (area_stp.value == "") {
var minArea_as = "\"\"";
} else {
var minArea_as = area_stp.value;
}
var curveFit_as = _root.curve_cb.value;
var corner_as = _root.corner_cb.value;
//注釋2
var str = "var cur_tl = fl.getDocumentDOM().getTimeline();"+"var curFrame, startKF, endKF;"+"var newSel = new Array();"+"try {"+"startKF = eval("+startKF_as+"-1);"+"endKF = eval("+endKF_as+"-1);"+"var threshold = "+threshold_as+";"+"var minArea = "+minArea_as+";"+"var curveFit = \""+curveFit_as+"\";"+"var corner = \""+corner_as+"\";"+"var errorMessage = \"\";"+"function theErrorMessage(msg){"+"if (errorMessage == \"\"){"+"errorMessage = msg;"+"}"+"else{"+"errorMessage += \"\\n\"+msg;"+"};"+"};"+"var thresholdErrorCondition = threshold==\"\" threshold < 1 threshold > 500;"+"var minAreaErrorCondition = minArea==\"\" minArea > 1000 minArea < 1 ;"+"if(startKF <=-1 endKF==-1 thresholdErrorCondition minAreaErrorCondition){"+"if(startKF == -1){"+"theErrorMessage(\"Please enter a start frame.\");"+"};"+"if(startKF < -1){"+"theErrorMessage(\"The start frame you specified does not exist.\");"+"};"+"if(endKF == -1){"+"theErrorMessage(\"Please enter an end frame.\");"+"};"+"if(endKF < -1){"+"theErrorMessage (\"The end frame you specified does not exist.\");"+"};"+"if(thresholdErrorCondition){"+"theErrorMessage (\"Please enter a value for Threshold between 1 - 500.\");"+"};"+"if( minAreaErrorCondition){"+"theErrorMessage (\"Please enter a value for Minimum Area between 1 - 1000.\");"+"};"+"alert(errorMessage);"+"}"+"else{"+"for (var k=0; k //注釋3
MMExecute(str);
}
//注釋4
submit_btn.addEventListener("click", this);
注釋1:檢查各個(gè)組件的值,如果為空的話,則設(shè)置為“”。
注釋2:構(gòu)造一個(gè)Java Script字符串。有興趣的話,可以找點(diǎn)相關(guān)的資料來看看,不會(huì)太難。(ActionScript 1.0跟JavaScript是非常像的。)
注釋3:執(zhí)行生成的JavaScript字符串。
注釋4:在Button組件submit_btn上面?zhèn)陕狘c(diǎn)擊事件。
三、實(shí)際用途
嚴(yán)格來說,本實(shí)例只能算是一個(gè)半成品,不過實(shí)例所提供的思路很有啟發(fā)性:怎么利用Numeric Stepper,怎么生成JavaScript字符串,怎么檢查組件的值,等等,都很值得我們學(xué)習(xí)。這在制作網(wǎng)頁表單,收集信息等場(chǎng)合中是非常有用的。