2023信创独角兽企业100强
全世界各行各业联合起来,internet一定要实现!

Flash MX 2004新特性实例学习七

2004-02-12 eNet&Ciweek

  实例八、Trace Bitmap Panel

  一、涉及特性

  本实例不太复杂,主要涉及组件的应用、对组件的编程和对JavaScript的应用,都是Flash MX 2004中的新特性。

  二、制作过程

  1、从组件栏中拖四个Numeric Stepper到场景中,分别设置属性如下:A、命名为start_stp,设置Maximum为10000,设置Minimum为1,step为1,value为100;B、命名为end_stp,设置Maximum为10000,设置Minimum为0,step为1,value为100;C、命名为color_stp,设置Maximum为100,设置Minimum为0,step为1,value为100;D、命名为area_stp,设置Maximum为500,设置Minimum为0,step为1,value为10。

  2、从组件栏中拖两个Combo Box到场景中,分别设置属性如下:A、命名为curve_cb,设置labels为“[normal, very tight, pixels, smooth, very smooth]”,设置rowCount为5;B、命名为corner_cb,设置labels为“[normal, many corners, few corners]”,设置rowCount为5。

  3、从组件栏中拖一个Button到场景中,命名为submit_btn,设置Labels为Submit。然后排列所有组件如图1所示。

  

  4、在TimeLine中新建一个图层,命名为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:检查各个组件的值,如果为空的话,则设置为“”。

    注释2:构造一个Java Script字符串。有兴趣的话,可以找点相关的资料来看看,不会太难。(ActionScript 1.0跟JavaScript是非常像的。)

    注释3:执行生成的JavaScript字符串。

    注释4:在Button组件submit_btn上面侦听点击事件。

  三、实际用途

  严格来说,本实例只能算是一个半成品,不过实例所提供的思路很有启发性:怎么利用Numeric Stepper,怎么生成JavaScript字符串,怎么检查组件的值,等等,都很值得我们学习。这在制作网页表单,收集信息等场合中是非常有用的。

  

相关频道: eNews

您对本文或本站有任何意见,请在下方提交,谢谢!

投稿信箱:tougao@enet16.com