Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3800570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:54:49+00:00 2026-05-19T13:54:49+00:00

I’ve been following a tutorial written for Actionscript 2, and have successfully converted it

  • 0

I’ve been following a tutorial written for Actionscript 2, and have successfully converted it to AS 3, however on the second to last part I’m stuck.

The tutorial here (http://www.cleverpig.com/tutorials/whackapig/whack.htm step 8) has the following piece of code:

if (_currentframe==1) {
    // randomly choose whether or not to play
    if (random(100)>97) {
      // should we tease or popup?
      if (random(3)<1) {
        this.gotoAndPlay ("popup");
      } else {
        this.gotoAndPlay (1);
      }
    }
  }

it is meant to add some randomness to the character’s movement. After some googling I created this code in AS 3 hoping it would work.

if (currentFrame==1) {
    // randomly choose whether or not to play
    if(Math.floor(Math.random()*99)-97) {
      // should we tease or popup?
      if (Math.floor(Math.random() *3)-1)
   ) {
        this.gotoAndPlay ("popup");
      } else {
        this.gotoAndPlay (1);
      }
    }
  }

When I run the program with this code the character’s entire animation plays once (down, halfway up, up, hit). It is supposed to only play the first 3 frames, and repeat this.

EDIT:

function random (n:int ) : int {
    return Math.floor (Math.random() * n);
}

if (currentFrame==1) {
    // randomly choose whether or not to play
    if(random(100)): 97 {
      // should we tease or popup?
      if (random(3)): 1
      {
        this.gotoAndPlay ("popup");
      } else {
        this.gotoAndPlay (1);
      }
    }
  }

Symbol ‘hole’, Layer ‘Actionscript’, Frame 1, Line 10 1084: Syntax error: expecting identifier before colon.
Symbol ‘hole’, Layer ‘Actionscript’, Frame 1, Line 10 1008: Attribute is invalid.
Symbol ‘hole’, Layer ‘Actionscript’, Frame 1, Line 12 1084: Syntax error: expecting identifier before colon.
Symbol ‘hole’, Layer ‘Actionscript’, Frame 1, Line 13 1008: Attribute is invalid.
Symbol ‘hole’, Layer ‘Actionscript’, Frame 1, Line 15 1083: Syntax error: else is unexpected.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:54:50+00:00Added an answer on May 19, 2026 at 1:54 pm

    I’d give a -1 to the writer of the original tutorial, putting a numeric random expression in a a conditional like that.

    To determine the outcome of a conditional’s expression, it is always evaluated as a Boolean. If you put a Number/int in there, it will be false only if its value is 0(.0). In all other cases (including negative numbers) it will evaluate to true.

    Yes, you can make an easier random() function by following @weltraumpirat’s answer, but I’d rather recommend you take the random() function out of the conditional and wrap it in a chance() method of sorts. For example:

    function feelingLucky(ratio:Number):Boolean {
        return Math.random() <= ratio;
    }
    

    Then calling this method will give you a better x out of y syntax like:

    if (feelingLucky(97/99)) {
        // you're lucky.
    } else {
        // not so lucky.
    }
    

    Or your other conditional, feelingLucky(1/3). Or try a winning streak with feelingLucky(100/100).

    Good luck 🙂

    P.S. Your recent edit fails because of the colons and numeral :97 after the if statements. They shouldn’t be there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.