• home
  • forum
  • my
  • kt
  • download
  • Basics on Variavles

    Author: 2008-09-28 10:24:10 From:

    Variables are incredibely easy to grasp! As you get to know ActionScript well... you'll realize that these handy bunchfull is well... handy. Anyway, cut the chase! Lets get on with variables. If you know variables with other languages like PHP or ASP, for example - then you'll be able to understand these incredibely easy.

    Firstly, you need to declare a variable like this:

    (for CS3)
    var someText:String = "Hello... this is some text!";
    (for MX)
    var someText = "Hello... this is some text!";

    Under CS3 the :String is to tell actionscript that we want a string-based variable. For example if we wanted a number-based variable we would use :Number.

    Now if we wanted to store a number, we would use the same technique, however we wouldn't use quotations around the value - the same for variable names!

    var someNumber = 5727738;

    Now in the matter of storing another variables value is actually pretty easy. To do this you'd just store the variable's name as the value, and it will copy the copied variable's stored value (if that all makes sense!)

    var someText = "Hello... I am going to be copied!";
    var someOtherText = someText;

    So now someOtherText would have the same stored value as someText. Now, suppose you want to do some maths in your numerical variables? Simple, read below!

    var maths_rubbish = 5 + 5;

    So basically here the variable maths_rubbish would have the value 10. And if you used 5 - 5 - well, the answer would obviously be 0.

    The next tecchnique is incredibely handy - you could use this to add 2 variables stored values onto your new variable:

    var oldVar = "Hi!";
    var oldVar2 = "and bye!";
    var newVar = oldVar + oldVar2 + ". No, infact - hi again!";

    So basically newVar would have the following text stored: Hi! and bye! No, infact - hi again!";

    Now, remember if you are using CS3 or similar versions of Adobe Flash then you would need to declare your variables as strings before it would work (as explained near the start of this tutorial)

    Now boleans. Pretty simple; they mean true or false. You don't use quotations around the value, otherwise they'd be classed as strings.

    var trueVar = true;
    var falseVar = false;

    These will become useful later on in ActionScript.

    Well that's it for now! I hope you learnt something out of it - if not, well that's wasted 30 mins of your time! Anyway, no fear! If you need help post a comment below please - I do check them often :).

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      3D (20)
      Math Physics (14)
      3rd Party (5)
      Navigation (60)
      Actionscripting (26)
      Optimization (16)
      Animation (32)
      Projector (9)
      Audio (46)
      Special Effects (112)
      Backend (25)
      Text Effects (65)
      Drawing (18)
      Tips and Techniques (41)
      Dynamic Content (25)
      Tricks (6)
      Games (66)
      Utilities (19)
      Getting Started (82)
      Video (24)
      Interactivity (43)
      Web Design (29)

    New

    Hot