0

Is there anything wrong with this function?

Im trying to learn actionscript

public function navigateToFrame(frameNo:Number)
 {
        var firstNumber:Number = 25;
        var secondNumber:Number = 1;
        trace("crap..."+firstNumber);
        frameNo  =  firstNumber * (frameNo - secondNumber);
        trace("crap..."+frameNo);
        frameNo =  frameNo + secondNumber;
        trace("crap..."+frameNo);
        _root.gotoAndStop(frameNo);
  }

I get a compile error that goes like 'Syntax error.

Mnyikka
  • 1,223
  • 17
  • 12

2 Answers2

4

Since you tagged this with actionsript-3, I would say that firstly, you are trying to use _root, and unless you happen to have a member variable of the same name, then this will not work.

The keyword for the root in as3 is root, not _root

sberry
  • 128,281
  • 18
  • 138
  • 165
  • Hi guys thanks for your answer, this worked var frameNo:Number function navigateToFrame(frameNo) { var firstNumber:Number; var secondNumber:Number; var frameNoVar:Number; firstNumber = 25; secondNumber = 1; frameNoVar = 10; trace("crap..." + firstNumber); frameNoVar = firstNumber * (frameNo - secondNumber); trace("crap..." + frameNoVar); frameNoVar = frameNo + secondNumber; trace("crap..." + frameNoVar); Object(root).gotoAndStop(frameNo); } – Mnyikka Jan 09 '12 at 08:29
  • @Mnyikka If this answered your question, you should accept the answer (that's the big check icon on the left). Also, please remove all the unreadable code from your comment above - it is not going to help anyone. If anything else than the `root` call has changed, you can edit and post code snippets to your original question, otherwise just leave the answer as is; it is fairly straight-forward. – weltraumpirat Jan 09 '12 at 10:06
-1

In your script, you didn't declare the frameNo variable which is required in AS3, instead you're declaring it a function parameter and then trying to set its value within the function, which doesn't make much sense because whatever the value of that parameter is when you call the function, it would not be used. Also, in AS3, the reference for root is stored in an object property called root.

Change your code to this and give it a try:

public function navigateToFrame(frameNo:Number)
 {
    var firstNumber:Number = 25;
    var secondNumber:Number = 1;
    var frameNoVar:Number
    trace("crap..." + firstNumber);
    frameNoVar = firstNumber * (frameNo - secondNumber);
    trace("crap..." + frameNoVar);
    frameNoVar = frameNo + secondNumber;
    trace("crap..." + frameNoVar);
    Object(root).gotoAndStop(frameNo);
  }
IneedHelp
  • 1,630
  • 1
  • 27
  • 58
  • There is nothing wrong with the way `frameNo` is being used. It is declared implicitly by being a parameter in the function signature. – sberry Jan 09 '12 at 07:57
  • That's what I said too, but I wasn't sure about the purpose of your function. I thought you wanted to do some tracing and still go to and stop at the specified frame. Still, your code shouldn't have gave you a syntax error, just a undefined property access error. – IneedHelp Jan 09 '12 at 08:22