Actionscript代码错误

时间:2017-09-25 13:54:09

标签: actionscript-3 flash actionscript flash-cs4 error-code

我目前正在货币柜台上开展个人项目,我的代码真的很困难。如果有人可以帮助我,那么带有答案的最终文本框不会显示在我的项目中。

该项目是一个货币计算器,包括1¢,5¢,10¢,25¢,1 $& 2 $

我的代码:

package {
    import flash.display.*;
    import flash.text.*;
    import flash.events.MouseEvent;

    public class U1A4_Monnaie extends MovieClip {

        private var monMessage:TextField=new TextField; 
        private var maMiseEnForme:TextFormat=new TextFormat;


        public function U1A4_Monnaie():void
        {

            btnSoumettre.addEventListener(MouseEvent.CLICK, calculeMonnaie);

        }

        private function calculeMonnaie(event:MouseEvent):void {


            maMiseEnForme.font="Arial";
            maMiseEnForme.size=20;
            maMiseEnForme.bold=true;
            maMiseEnForme.color=0x660000;
            monMessage.x=20;
            monMessage.y=190;

            monMessage.autoSize=TextFieldAutoSize.LEFT;
            monMessage.border=true;
            monMessage.defaultTextFormat=maMiseEnForme;


            var somme:Number;
            var totalCents:int;
            var pieces25Cents:int=0;
            var pieces10Cents:int=0;
            var pieces5Cents:int=0;
            var pieces1Cent:int=0;
            var restant:int=0;
            var nouvMessage:String;

            somme = Number(montant.text);
            totalCents = int(somme * 100);


            pieces25Cents = totalCents / 25;
            restant= totalCents % 25;

            pieces10Cents = restant  / 10;
            restant = restant % 10;

            pieces5Cents = restant / 5;
            restant = restant % 5;

            pieces1Cent = restant;

            montant.text=" ";

            nouvMessage =("Montant à transformer en monnaie: " + somme + "$" + 
                          "\n\n25 cents: " + pieces25Cents + 
                          "\n10 cents: " + pieces10Cents + 
                          "\n5 cents: " + pieces5Cents + 
                          "\n1 cent: " + pieces1Cent);

            monMessage.text=nouvMessage;
            addChild(monMessage);

        }
    }
}

1 个答案:

答案 0 :(得分:1)

缺少一些参考文献:“montant”和“btnSoumettre”。 也许这会有所帮助:

package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.text.TextInteractionMode;

public class U1A4_Monnaie extends MovieClip {

    private var monMessage:TextField=new TextField; 
    private var maMiseEnForme:TextFormat=new TextFormat;
    **private var btnSoumettre:Sprite;
    private var montant:TextField=new TextField;** 

    public function U1A4_Monnaie():void
    {
        montant = new TextField();
        montant.border=true;
        montant.text = "100";
        montant.height = 20;
        montant.type = TextFieldType.INPUT;
        this.addChild(montant);

        btnSoumettre = new Sprite();
        btnSoumettre.y = 22;
        btnSoumettre.graphics.beginFill(0xFF0000, 1);
        btnSoumettre.graphics.drawRect(0, 0, 100, 20);
        btnSoumettre.graphics.endFill();
        this.addChild(btnSoumettre);
        btnSoumettre.addEventListener(MouseEvent.CLICK, calculeMonnaie);



    }

    private function calculeMonnaie(event:MouseEvent):void {


        maMiseEnForme.font="Arial";
        maMiseEnForme.size=20;
        maMiseEnForme.bold=true;
        maMiseEnForme.color=0x660000;
        monMessage.x=20;
        monMessage.y=190;

        monMessage.autoSize=TextFieldAutoSize.LEFT;
        monMessage.border=true;
        monMessage.defaultTextFormat=maMiseEnForme;


        var somme:Number;
        var totalCents:int;
        var pieces25Cents:int=0;
        var pieces10Cents:int=0;
        var pieces5Cents:int=0;
        var pieces1Cent:int=0;
        var restant:int=0;
        var nouvMessage:String;

        somme = Number(montant.text);
        totalCents = int(somme * 100);


        pieces25Cents = totalCents / 25;
        restant= totalCents % 25;

        pieces10Cents = restant  / 10;
        restant = restant % 10;

        pieces5Cents = restant / 5;
        restant = restant % 5;

        pieces1Cent = restant;

        montant.text=" ";

        nouvMessage =("Montant à transformer en monnaie: " + somme + "$" + 
            "\n\n25 cents: " + pieces25Cents + 
            "\n10 cents: " + pieces10Cents + 
            "\n5 cents: " + pieces5Cents + 
            "\n1 cent: " + pieces1Cent);

        monMessage.text=nouvMessage;
        addChild(monMessage);

    }
}

}