1084:语法错误:在函数之前期待rightbrace

时间:2017-09-27 15:57:18

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

我是as3的新手,你能不能帮我。

收到此错误1084:语法错误:在函数之前期待rightbrace。

如果您想要其他代码,请告诉我们。这一行可能无法解释所有需要的信息。

public function U1A4_Monnaie():void
    {

修改

这是原始代码。我计算了关闭和打开括号的数量,它们似乎相互匹配,但我可能错了......

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 {


        nouvMessage.font="Arial";
        nouvMessage.size=20;
        nouvMessage.bold=true;
        nouvMessage.color=0xFFFFFF;
        nouvMessage.x=20;
        nouvMessage.y=20;

        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 + "$" + 
            "\n25 cents: " + pieces25Cents + 
            "\n10 cents: " + pieces10Cents + 
            "\n5 cents: " + pieces5Cents + 
            "\n1 cent: " + pieces1Cent);

        trace()monMessage.text=nouvMessage;
        addChild(monMessage);

    }
}

1 个答案:

答案 0 :(得分:2)

该错误有时可能是欺骗性的,因为即使所有括号都存在,它也可能被抛出。

在您的情况下,问题是这一行(第二行到最后一行代码):

trace()monMessage.text=nouvMessage; 

trace()之后应该有一个终结符将它与下一个字符分开。

trace(); monMessage.text=nouvMessage;

或者(因为空迹很无意义)或许你的意思是做以下事情:

trace(monMessage.text = nouvMessage); 

将跟踪monMessage.text的更新值。

虽然大多数人可能会认为这更清洁:

monMessage.text = mouvMessage;
trace(monMessage.text);