动作脚本代码错误

Posted

技术标签:

【中文标题】动作脚本代码错误【英文标题】:Actionscript code errors 【发布时间】:2018-03-06 12:36:47 【问题描述】:

我目前正在做一个关于收银台的个人项目,我的代码真的很卡。如果有人可以帮助我,带有答案的最终文本框不会出现在我的项目中。

该项目是一个货币计算器,包括 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);

        
    

【问题讨论】:

使用 Debug 选项,而不是 Test Movie 来查看错误。有任何错误信息吗?为什么nouvMessage = 内容放在括号内? 【参考方案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);

    

【讨论】:

谢谢。我仍在尝试找出其余代码以使一切正常。将整个文件发送给您有用吗?我有一个链接的框和按钮以及所有内容。我认为这个方程没有明确的视觉价值。 在此处发布文件。

以上是关于动作脚本代码错误的主要内容,如果未能解决你的问题,请参考以下文章

Flash 动作脚本 tweenlite 1084

动作脚本 3 滑动功能(不会滑动)

如何知道是动作脚本 1、动作脚本 2 还是动作脚本 3?

在单个动作脚本中编写多个按钮(几乎相同)的问题

高分求教按键精灵2个脚本代码,即颜色符合执行鼠标动作。

在不同的框架中初始化代码(在动作脚本文件中)