1119:通过静态类型flash.utils:Timer的引用访问可能未定义的属性alpha。

时间:2012-06-18 22:00:38

标签: actionscript-3

我遇到了这个脚本的问题...除了点击之外,其中的所有内容都在工作。这是一个二进制时钟,我想调暗光线

package{
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import com.greensock.*;
import com.greensock.easing.*;
import flash.events.TouchEvent;

public class Main extends MovieClip
{
    var clock:Timer=new Timer(1000);
    var date:Date=new Date();
    var hr:int;
    var min:int;
    var sec:int;
    var bits:Array;

    public function Main()
    {
        init();
        tvinnet.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);
    }

    private function init():void
    {
        sec=date.getSeconds();
        min=date.getMinutes();
        hr=date.getHours();
        turnBits(converter(sec),'S');
        turnBits(converter(min),'M');
        turnBits(converter(hr),'H');
        clock.start();
        clock.addEventListener(TimerEvent.TIMER, setTime);

    }



    function fl_MouseOverHandler(e:MouseEvent):void
    {
            clock.alpha = 0;
    }




    private function setTime(e:TimerEvent):void
    {
        date=new Date();
        sec=date.getSeconds();
        min=date.getMinutes();
        hr=date.getHours();
        turnBits(converter(sec),'S');
        turnBits(converter(min),'M');
        turnBits(converter(hr),'H');
    }

    private function dec2bin(dec:int, length:int)
    {
        var bin:Array= new Array();
        while((dec/2)>0)
        {
            bin.push(dec%2);
            dec=dec/2;
        }
        while(bin.length<length) bin.push(0);
        return bin;
    }

    private function converter(num:int)
    {
        var st:String=String(num);
        if(st.length==1)st='0'+st;
        var fDigit:int=int(st.charAt(1));
        var sDigit:int=int(st.charAt(0));
        var fColumn:Array=dec2bin(fDigit,4);
        var sColumn:Array=dec2bin(sDigit,3);
        var result:Array=fColumn.concat(sColumn);
        return result;
    }

    private function turnBits(newBits:Array, target:String)
    {
        for(var a:int=0;a<newBits.length;a++)
        {
            if((a!=6)||(target!="H"))
            {
                if(newBits[a]==0) TweenMax.to(this.getChildByName(target+String(a)), 1, {glowFilter:{color:0x00cbff, alpha:0, blurX:15, blurY:15,strength:1},alpha:.1});
                else TweenMax.to(this.getChildByName(target+String(a)), 1, {glowFilter:{color:0x00cbff, alpha:1, blurX:20, blurY:20,strength:.8},alpha:1});
            }
        }
    }
}   

}

所以,如果你很棒,你能找到任何东西吗?

1 个答案:

答案 0 :(得分:2)

您将时钟变量定义为Timer,然后您尝试访问其在Timer中不可用的alpha属性。

function fl_MouseOverHandler(e:MouseEvent):void
    {
            clock.alpha = 0; //wrong approach, use this.alpha = 0;
    }