FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Actionscript2.0 - Difference between var :Object and new Obj

 


mothmann
whats the difference between saying

var box:Object;

and

box = new Object();

i know var box:Object; passes syntax but will trace undefined I just don't understand why it is there as an option.

and what is the difference between using

var box = new Object();
and
box = new Object();
makli
Hi,

the difference between

Code:
var myObj:Object;


and

Code:
myObj=new Object();


is, that with the first statement you declare a variable with a type of object.

The second statement creates a new object and assigns the newly created object to the variable myObj.

Therefore, when you try to access myObj before the second statement, you will get an "undefined" message. After assigning an object, you can access this object via the variable myObj.

HTH

Makli
mothmann
ok that makes sense. but what about my 2nd question?

what is the difference between using

var box = new Object();
and
box = new Object();
makli
When you use

var myObject:Object;

you declare a local variable in the codeblock, where you place the declaration. Only when you use the var-statement, you can use strict typing.

A variable you have already declared cannot be declared again as a local variable.

HTH

Makli
mothmann
how do local varibles work in flash? are they local to that scene?

and how is it declared if you do not use var?
awesty
var myNumber:Numer = 5;

is the same as

myNumber = 5;

The first one is just strict data typing.

They are both local to that code block. If you want a variable that is accessable anywhere on that frame, declare it like this:

_root.myNumer = 5;

And in the whole timeline:

_global.myNumber = 5;

Dont use scenes when using actionscript.
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.