FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free 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.
Related topics
Site Nav Suggestions...
Search function
Random Quotes Services for anyone - 1 Frih$ for 170+ quotes
Can l get a css document to
subject javascript code please help
Java tutorials
Need help with javascript
AJAX tutorial [2nd part now updated]
Difference between EDIT and NEW?
Flash websites
PHP not working
fatal error in Joomla installation "index.php"
Extraer los canales de color en una imagen a color
How Java is different than Javascript !!
Reply to topic    Frihost Forum Index -> Scripting -> Others

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