Skip to main content
_Moveon21
Inspiring
March 8, 2013
Question

need help in some basic syntax and symantec rule of AS eg var abc:*?

  • March 8, 2013
  • 2 replies
  • 602 views

I want to know what this following lines in action script signify

1)var  abc:*;

is this mean it can take any kind of value ?


2)var abc:Function;

This topic has been closed for replies.

2 replies

Inspiring
March 8, 2013

1) Asterisks in variable declaration means that it can be any datatype. Basically you instruct Flash to treat it as anything.

For example

var abc:*;

abc = 2; // assigned integer and all good

abc = new MovieClip() // again - all good

abc = "haha" // still takes it

2) Means that var abc is a Function. You promise to Flash that when you assign value - value will be Function only.

var abc:Function;

abc  = new Function () // all good

abc = 2; // error because int is not Function

abc = new MovieClip() // error - MovieClip is not Function

abc = "haha" // error = "haha" is a string and not a Function

Any object in AS3 has a datatype.

Inspiring
March 8, 2013

The following code:

import flash.utils.describeType;

var abc:*;

abc = new Object();

describe(abc);

abc = new Function();

describe(abc);

abc = new MovieClip();

describe(abc);

function describe(_abc:*):void

{

    var description:XML = describeType(_abc);

    trace("Properties:\n------------------");

    for each (var a:XML in description.accessor)

    {

        trace(a.@name+" : "+a.@type);

    }

    trace("\n\nMethods:\n------------------");

    for each (var m:XML in description.method)

    {

        trace(m.@name+" : "+m.@returnType);

        if (m.parameter != undefined)

        {

            trace("     arguments");

            for each (var p:XML in m.parameter)

            {

                trace("               - "+p.@type);

            }

        }

    }

}

produces this:

Properties:

------------------

Methods:

------------------

Properties:

------------------

length : int

prototype : *

Methods:

------------------

Properties:

------------------

accessibilityImplementation : flash.accessibility::AccessibilityImplementation

...

currentLabels : Array

Methods:

------------------

addChild : flash.display::DisplayObject

     arguments

...

removeChild : flash.display::DisplayObject

     arguments

               - flash.display::DisplayObject

play : void