1084: Syntax error: expecting rightbrace before function

1084: Syntax error: expecting rightbrace before function

我是 as3 的新手,你能帮帮我吗?

收到此错误 1084:语法错误:函数前需要右括号。

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

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);

    }
}

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

在您的情况下,问题出在这一行(代码的倒数第二行):

trace()monMessage.text=nouvMessage; 

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

trace(); monMessage.text=nouvMessage;

或者(因为空迹毫无意义)也许您打算执行以下操作:

trace(monMessage.text = nouvMessage); 

这将跟踪 monMessage.text 的更新值。

虽然大多数人可能会同意这样更干净:

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