Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 1067:将Class类型的值隐式强制到不相关的类型函数_Actionscript 3 - Fatal编程技术网

Actionscript 3 1067:将Class类型的值隐式强制到不相关的类型函数

Actionscript 3 1067:将Class类型的值隐式强制到不相关的类型函数,actionscript-3,Actionscript 3,我正在为我的课程做一个Flash项目。我是个新手,似乎无法让任何东西正常工作(我放弃了文档类) 我的问题是我有一个计时器,它会根据给定的值在每个刻度上加上一些整数。但这不是问题所在,我的代码不允许计时器工作,它在一个名为“CounterCode”的类中,当我让计时器转到“CounterA”函数时,它说“Error#1007:尝试在非构造函数上实例化”,所以现在我将它发送到CounterCode构造函数,它给出了上述错误 我会给出一段代码,但如果需要的话,我会要求更多,我并没有做Flash太长时间

我正在为我的课程做一个Flash项目。我是个新手,似乎无法让任何东西正常工作(我放弃了文档类)

我的问题是我有一个计时器,它会根据给定的值在每个刻度上加上一些整数。但这不是问题所在,我的代码不允许计时器工作,它在一个名为“CounterCode”的类中,当我让计时器转到“CounterA”函数时,它说“Error#1007:尝试在非构造函数上实例化”,所以现在我将它发送到CounterCode构造函数,它给出了上述错误

我会给出一段代码,但如果需要的话,我会要求更多,我并没有做Flash太长时间,所以请原谅任何值得畏缩的代码

public static var turnTimer:Timer = new Timer(500, 100);
    turnTimer.addEventListener(TimerEvent.TIMER, CounterCode);


    public function CounterCode(Event:TimerEvent):void {
这似乎是问题所在,但我似乎不知道它是什么,我搜索了很多,但它似乎与我的问题无关

--用完整代码编辑--

}


谢谢

您不能将构造函数用作侦听器。我测试了您的代码。它很好用。我认为问题不在这些方面。检查错误行数。该代码根本无法正常工作,您误解了设置。CounterCode不是方法,而是类CounterCode的构造函数。现在再次尝试该设置,看看是否工作正常。感谢回复!BotMaster,当我使用另一个函数而不是构造函数时,它会给出1007错误。有什么想法吗?同样的代码只是说“计数器A”,而不是计时器中的“计数器代码”。再次感谢!
package  {

import Fighter;
import Rogue;
import Mage;
import Healer;
import MonsterOne;
import MonsterTwo;
import MonsterThree;
import MonsterFour;
import turn;

import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;

public class CounterCode extends MovieClip {

    public static var fighterCount:int = 0;
    public static var rogueCount:int = 0;
    public static var mageCount:int = 0;
    public static var healerCount:int = 0;
    public static var fullCount:Number = 100;
    public static var monsCount:Number = 0;
    public static var whoTurn = String(whoTurn);
    public static var turnFighter:MovieClip = turnFighter as MovieClip;
    public static var turnRogue:MovieClip = turnRogue as MovieClip;
    public static var turnMage:MovieClip = turnMage as MovieClip;
    public static var turnHealer:MovieClip = turnHealer as MovieClip;

    public static var tGo = new tGo();

    public static var turnTimer:Timer = new Timer(500, 100);
    turnTimer.addEventListener(TimerEvent.TIMER, CounterCode);


    public function CounterCode(Event:TimerEvent):void {
        var randChoice;
        trace(fighterCount);
        fighterCount += Fighter.aSpeed;
        rogueCount += Rogue.aSpeed;
        mageCount += Mage.aSpeed;
        healerCount += Healer.aSpeed;

        if(monsCount >= 100) {
            whoTurn = "monT";
            turnTimer.stop();
            randChoice();
        }

        if(fighterCount >= 100) {
            whoTurn = "fighterT";
            turnTimer.stop();
            trace("stop");
            tGo();
        }

         if(rogueCount >= 100) {
            whoTurn = "rogueT";
            turnTimer.stop();
            tGo();
        }

        if(mageCount >= 100) {
            whoTurn = "mageT";
            turnTimer.stop();
            tGo();
        }

        if(healerCount >= 100) {
            whoTurn = "healerT";
            turnTimer.stop();
            tGo();
        }
    }       
}