1

I'm new to as3 can you help me please.

getting this error 1084: Syntax error: expecting rightbrace before function.

Please let me know if you would like the rest of the code. This one line might not explain all of the needed information.

public function U1A4_Monnaie():void
    {

EDIT

Here is the original code. I counted the amount of brackets both closing and opening, and they seem to match up with eachother, but I might be wrong...

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

    }
}
Larocque
  • 27
  • 7
  • Possibly remove the `:void` – Geeky I Sep 27 '17 at 16:08
  • Did not work. I am trying to figure it out but still have no luck. Thanks for the help though! – Larocque Sep 27 '17 at 16:28
  • The script you provided has no problems. The mistake is probably before these lines. – Organis Sep 27 '17 at 18:23
  • This can't be real... See if [**this image**](http://slideplayer.com/slide/6004454/20/images/15/%7B+Left+(opening)+bracket.jpg) helps you to _"figure it out"_. Hint: If you open a function (eg: to add instructions) you must also close it. Make sure all your functions open/close correctly. Also don't put functions inside other functions if new to coding... – VC.One Sep 27 '17 at 18:31
  • Could I send in my whole code and maybe I can find the problem? – Larocque Sep 27 '17 at 20:39
  • @Larocque it's simple. Every opening `{` must have a closing `}`... If function `U1A4_Monnaie` has the correct number of `{` and matching number of `}` then it must be previous function that has issues. Check it too and if it's fine keep checking by going upwards towards start of your program. Check Functions or For/While loops or anything else that has a `{` but has no matching `}`... – VC.One Sep 27 '17 at 23:08
  • Updated, I was looking around and cant find anything out of the ordinary. – Larocque Sep 27 '17 at 23:24
  • @Larocque - did you solve your problem? – BadFeelingAboutThis Oct 02 '17 at 17:34
  • I did, thanks for your help! I used your help and others to solve my problem – Larocque Oct 05 '17 at 21:42

1 Answers1

2

That error can sometimes be deceiving because it can be thrown even if the all the brackets are there.

In your case, the issue is this line (second to last line of code):

trace()monMessage.text=nouvMessage; 

There should be a terminator after trace() to separate it from the next character.

trace(); monMessage.text=nouvMessage;

Or (since an empty trace is rather pointless) perhaps you mean to do the following:

trace(monMessage.text = nouvMessage); 

which would trace the updated value of monMessage.text.

Though most would probably agree that this is cleaner:

monMessage.text = mouvMessage;
trace(monMessage.text);
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40