Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 3 of 3

Thread: Tutorial 1 the variables

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    Tutorial 1 the variables

    flash templates

    Actionscritp 3.0 - Tutorial 1
    The variables


    What are the variables?
    The easiest way to think about it is as a box.
    A box? Yes, just a simple box.
    This box can be given a name and can contain things. For Actionscript, it will have a name and contains values or objects.
    A box can contain different type of values so we will to start by telling our variable what type of values it can contain.
    A variable can be local or global:
    - local: if the variable is defined into a function or into a loop, so once the function code is carried out, the variable will be automatically deleted from the Flash?s memory. I will explain it to you later on in more details.
    - global: this variable is always kept in memory and so is always accessible

    This is the way to declare a variable:
    Code:
    var miles:Number;
    var declare the variable to Flash
    miles is the name of the variable
    :Number; is the type of value that the variable can contain. A numerical value in this case.

    Following the idea of the box. I tell Flash to create a box with a label name (miles) and also specify to Flash that the box can only contain values of numerical type such as 0, 3, 124, 0.4, 654.332?

    Now, I will assign a value to my variable the following way:

    Code:
    miles=10;
    PS: I also could have assign the value at the same time as the declaration the following way:

    Code:
    var miles:Number=10;
    Little parenthesis: :Number is define as the Data Type of the variable.
    With Actionscript 1.0, we were used to simply write var miles=10; and in the OOP there is nothing worst then doing so.
    As an advice, I recommend you to always specify the Data Type. If you wanted next to start writing code on an AS file, without the Data Type, Flash would return an error. So better get used to it from now on.

    Next, I write:

    Code:
    trace(miles);
    I tell Flash to show me what is in the box, so flash will open the box and will show me the value contained into it.
    I obtain the following output:
    10

    I said earlier on that the variable Miles can contain only numerical values as it has been data typed as Number (:Number).
    Let us see if it is correct and try to insert a value of String type into the variable miles:

    Code:
    miles='Davis';
    if I publish the SWF, Flash would return the following error:
    1067: Implicit coercion of a value of type String to an unrelated type Number.
    I tells me that the type of value is wrong and that I am trying to assign a String value to a variable data typed Number:

    Instead, if after writing var miles:Number=10; I would add:

    Code:
    miles=15;
    with a trace(miles), I would obtain the following output:
    10
    15


    We can understand now that we can change the value of the variable as wanted keeping in mind to always use the same data type declared

    With the following example, I add a value to the existing value of miles:

    Code:
    miles+=10;
    this syntax tells Flash:
    open the box named miles, take its value, add 10 and close again the box.
    Therefore, it adds a value of 10 to the already existing value.
    In fact with trace (miles); I get the following output:
    10
    15
    25

    It is the same as saying miles= miles+10;

    The spontaneous question is which types of values can I assign to a variable?
    Answer: every type of value of the built-in classes that exist in Flash, therefore Number, String, MovieClip, TextField, etc etc
    A complete list of the existing classes in Flash can be found to this link:

    Migration

    To help you better to understand, here are some few examples.

    I create a variable of type String and I assign to it a string value:

    Code:
    var my_name:String="filippo";
    and with trace(my_name) I obtain the following output:
    filippo

    it is important to write the string (as it is a string) in between the double quote ?filippo? otherwise if we would write:

    Code:
    var my_name:String=filippo;
    Flash would return the following error:
    1120: Access of undefined property filippo.
    rightly telling us that it cannot find any variable named filippo.
    In fact, if we write =filippo, Flash is looking for a variable with such name to assign its value to the variable ?my_name?.

    Another example, I create a variable of type MovieClip:

    Code:
    var clip:MovieClip=new MovieClip();
    in this case, we have a new syntax not seen before: the operator new.
    This operator allows Flash to understand that it has to create a new MovieClip as the variable clip will contain a MovieClip.
    So, using var clip:MovieClip=new MovieClip(); we are telling Flash to create a new empty MovieClip.
    Going further on, we should then create an instance of the MovieClip class but it is not yet the right time to get into this and at this point would only confuse the basic idea.

    Another example, I create a variable a type textField:

    Code:
    var field:TextField=new TextFiled();
    once again, we find the operator new.

    Stay tuned to learn more about it!

    Source files:
    Attached Files

  2. #2
    Flash :D Settled In andreipatrascu93 is on a distinguished road
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Re: Tutorial 1 the variables

    Thank you for this great tutorial. I'm trying to figure out AS3 but whenever I do this I don't have enough time or I get into a problem and I give up. Respect !

  3. #3
    Junior Member Settled In Meat4Grinder is on a distinguished road
    Join Date
    Aug 2010
    Posts
    1
    Rep Power
    0

    Re: Tutorial 1 the variables

    Anyone have downloaded the video's? Would like to talk to you and get your honest opinion if its a good investment or not.

+ Reply to Thread

Similar Threads

  1. variables and functions from child movieclip
    By coma in forum Actionscript 3.0 newbies
    Replies: 11
    Last Post: 19-06-10, 04:04
  2. Passing variables from HTML to Flash CS3
    By Flep in forum Tutorials
    Replies: 46
    Last Post: 07-05-10, 21:45
  3. declaring variables
    By Aaron24 in forum Flash English
    Replies: 9
    Last Post: 24-08-08, 20:43
  4. Declaring variables in AS 3.0
    By Pherankh in forum Actionscript 3.0 newbies
    Replies: 0
    Last Post: 24-06-08, 21:13
  5. Displaying PHP Variables in Flash
    By chosendesigns in forum PHP | mySQL | Flash CS3
    Replies: 1
    Last Post: 14-05-08, 12:49

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts