About

<#TEMPLATE_INCLUDE_NINEPAGE_ABOUTME#>
  • May

    29

    import flash.display.BitmapData;
    this.createEmptyMovieClip("input_mc",1);
    input_mc.createTextField("input_txt",1,0,0,100,20);
    input_mc.input_txt.border = true;
    input_mc.input_txt.type = "input";
    var txt_bmp:BitmapData = new BitmapData(input_mc._width+1, input_mc._height+1, true, 0x000000);
    txt_bmp.draw(input_mc);
    this.createEmptyMovieClip("show_txt",2);
    show_txt.attachBitmap(txt_bmp,1,"always",true);
    show_txt._x = 100;
    show_txt._y = 100;
    show_txt._rotation = 30;
    show_txt.onRelease = txtGetFocus;
    show_txt._alpha = 50;
    function txtGetFocus() {
     Selection.setFocus(input_mc.input_txt);
     input_mc.input_txt.onChanged = function() {
      txt_bmp = new BitmapData(input_mc._width+1, input_mc._height+1, true, 0x000000);
      txt_bmp.draw(input_mc);
      show_txt.attachBitmap(txt_bmp,1,"always",true);
      show_txt._alpha = 50;
     };
    }

    以上方法可以解决AS1/2动态文本需要嵌入字体造成文件变大的问题(但不适合非系统自带的字体,如果客户端未安装相应的字体是无法显示的或用自动会被设置字体代替)。最新的FLASH版本与AS3结合高级文本功能,旋转之后直接可以显示文本(同样不适合非系统自带的字体)。

    More...

    May

    29

    var _arr:Array = ["", "我", "爱", "我", "我们", "我们的家"];
    var out_arr:Array = [];
    function arr_string():Void {
     if (_arr.length>1) {
      for (var i:Number = 1; i<_arr.length; i++) {
       temp = _arr[i].split(_arr[0]);
       if (temp.length>1) {
        _arr[i] = temp.join("");
       }
      }
      out_arr.push(_arr[0]);
     } else {
      out_arr.push(_arr[0]);
      return;
     }
     _arr.splice(0,1);
     arr_string();
    }
    arr_string();
    trace(out_arr);
    //删除所有""空元素
    for (var i:Number = 0; i<out_arr.length; i++) {
     if (out_arr[i] == "") {
      out_arr.splice(i,1);
      i--;
     }
    }
    trace(out_arr);

    以上算法如需应用在AS3中,需要将Void小写,并标注变量类型。

     

     

    May

    29

    [AS1/2]鼠标双击

    • 0 Comments
    • Flash Platform

    AS3中默认有鼠标双击事件,但早期的AS1/2版本并没有相应的鼠标双击事件。自己编写了一个比较完美鼠标双击事件,综合了双击时二次鼠标坐标位置对比,以及二次鼠标点击的时间差:

    var mouseListener:Object = new Object();
    var orig_x:Number;
    var orig_y:Number;
    var double_click_time:Number = 200;//毫秒
    mouseListener.onMouseDown = function():Void  {
     if (orig_x == null) {
      orig_x = _xmouse;
      orig_y = _ymouse;
      mouse_move = false;
      trace("单击");
     } else {
      if (orig_x == _xmouse && orig_y == _ymouse) {
       double_click_fun();//双击事件
       orig_x = null;
       orig_y = null;
      }
     }
    };
    mouseListener.onMouseMove = function():Void  {
     mouse_move = true;
    };
    mouseListener.onMouseUp = function():Void  {
     if (mouse_move) {
      orig_x = null;
      orig_y = null;
     }
     mouse_move = false;
     var my_timed_process:Number = setTimeout(my_delayed_fun, double_click_time);
    };
    Mouse.addListener(mouseListener);
    function double_click_fun():Void {
     trace("双击");
    }
    function my_delayed_fun():Void {
     orig_x = null;
     orig_y = null;
    }

     

    Jan

    19

    [AS1/2/3]字符串unicode编/解码

    • 0 Comments
    • Flash Platform
    //字符串转换成unicode映射
    function unicode_escape(string:String):String {
        var _string:String = string;
        var _arr:Array = new Array();
        for (var n:Number = 0; n<_string.length; n++) {
            _arr[n] = "0x"+_string.charCodeAt(n).toString(16);
        }
        _string = _arr.join("/");
        return _string;
    }
    trace(unicode_escape("ab:c&*^&("));
    //unicode解码成字符串
    function unicode_unescape(string:String, delimiter:String):String {
        var _string:String = string;
        var _arr:Array = _string.split(delimiter);
        for (var n:Number = 0; n<_arr.length; n++) {
            _arr[n] = String.fromCharCode(_arr[n]);
        }
        _string = _arr.join("");
        return _string;
    }
    trace(unicode_unescape("0x61/0x62/0xff1a/0x63/0x26/0x2a/0x5e/0x26/0x28", "/"));

     

    Mar

    18

    已经存在的相同元素添加后缀,并且对已经存在的相同元素进行分类标号。(效果和windows系统的重命名功能一样。例如:aa,aa[1],bb,aa[2],bb[1],cc,d,aa[3]。)

    var my_array:Array=["aa","bb","cc","aa","bb","dd","af","fd","aa","bc"];
    function arrayFormat(_array:Array ):Array {
        var _i:Number=0;
        var _obj:Object={};
        while (_i<my_array.length) {
            _obj[my_array[_i]]?_obj[my_array[_i]].push(my_array[_i]+"("+_obj[my_array[_i]].length+")"):_obj[my_array[_i]]=[my_array[_i]];
            _i++;
        }
        _array=[];
        for (var _key:String in _obj) {
            _array=_array.concat(_obj[_key]);
        }
        return _array;
    }
    trace(arrayFormat(my_array));

     

    More...

    Mar

    13

    [AS1/2/3]常用 Trim

    • 0 Comments
    • Flash Platform
    function trimChar(theString,char) {
        while (theString.charAt(0) == char) {
            theString = theString.substring(1, theString.length);
        }
        while (theString.charAt(theString.length-1) == char) {
            theString = theString.substring(0, theString.length-1);
        }
        return theString;
    }
    trace(trimChar("     10      "," "));//10

    Feb

    21

    var _array:Array = ["1-10", "6", "24-28", "2-11", "14-16", "28"];
    var all_number_array:Array = new Array();
    for (var i:Number = 0; i<_array.length; i++) {
    var temp_array:Array = new Array();
    _array[i] = _array[i].split("-");
    if (_array[i].length == 2) {
      for (var j:Number = Number(_array[i][0]); j<=Number(_array[i][1]); j++) {
       temp_array.push(j);
      }
    } else if (_array[i].length == 1) {
      _array[i] = Number(_array[i].toString());
      temp_array = _array[i];
    }
    _array[i] = temp_array;
    trace("第"+i+"组: "+_array[i]);
    all_number_array = all_number_array.concat(_array[i]);
    }
    delete temp_array;
    trace("\n");
    trace("总 组: "+all_number_array);
    all_number_array.sort(1,Array.NUMERIC);
    trace("排 序: "+all_number_array);
    for (var i:Number = 0; i<all_number_array.length; i++) {
    if (all_number_array[i] == all_number_array[i+1]) {
      all_number_array[i] = "";
    }
    }
    var temp_array:Array = new Array();
    for (var i:Number = 0; i<all_number_array.length; i++) {
    if (all_number_array[i] != "") {
      temp_array.push(all_number_array[i]);
    }
    }
    all_number_array = temp_array;
    delete temp_array;
    trace("简 化: "+all_number_array);

    //以下为输出结果:
    //
    第0组: 1,2,3,4,5,6,7,8,9,10
    第1组: 6
    第2组: 24,25,26,27,28
    第3组: 2,3,4,5,6,7,8,9,10,11
    第4组: 14,15,16
    第5组: 28


    总 组: 1,2,3,4,5,6,7,8,9,10,6,24,25,26,27,28,2,3,4,5,6,7,8,9,10,11,14,15,16,28
    排 序: 1,2,2,3,3,4,4,5,5,6,6,6,7,7,8,8,9,9,10,10,11,14,15,16,24,25,26,27,28,28
    简 化: 1,2,3,4,5,6,7,8,9,10,11,14,15,16,24,25,26,27,28

     

    Jan

    31

    常用键值表

    • 0 Comments
    • Miscellaneous

    FLASH常用工具键盘键值表。

    Jan

    28

    自定义让数组元素从长至短(不是从大至小)的顺序排列。

    var _array:Array = new Array("a", "abc", "abcdefg", "ab", "h", "c", "bc", "dc");
    _array.sort(sortLength);
    trace(_array);//abcdefg,abc,ab,dc,bc,a,c,h
    function sortLength(_length1, _length2) {
        return _length2.length-_length1.length;
    }

     

    Jan

    27

    在蓝色理想看到一网友为了便于阅读,将一行过长的文本字符串使用了硬回车换行的方式后出现错误,所咨询的。其在AS中是对字符串是不能进行硬回车换行的,只能在字符串过长时它自动换行。如果一定要换行,可以使用“+”号换行的方法。这在很多书上好像没有指出过这种“+”号的使用方法,应该算是它的特殊用法,既实现了换行,又连接了字符串。

    //这里是错误的使用方法
    my_txt = "当一行文本过长的时候,
              请不要使用硬回车换行,
              而是需要使用+连接。"
    ;
    trace(my_txt);

     

    //正确的使用方法
    my_txt = "当一行文本过长的时候,"
            +"请不要使用硬回车换行,"
            +"而是需要使用+连接。";
    trace(my_txt);