Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: Access vars declared outside class

(78 views • 5 replies)

This topic is 1 page long.

<< < > >>
None

Gutya

Reply To Post Reply & Quote

Posted at: 6/15/08 10:10 AM

Gutya FAB LEVEL 07

Sign-Up: 11/27/06

Posts: 777

I have declared some variables on a frame, and I'm having trouble working out how I can access them from inside a class file.

AS3, by the way.


None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 6/15/08 10:15 AM

GuyWithHisComp LIGHT LEVEL 23

Sign-Up: 11/10/05

Posts: 4,029

class:

package 
{
	public class ClassName
	{
		private var refObj:Object;
		public function passVariables(obj:Object):void
		{
			refObj = obj;
		}
	}
}

frame:

var obj:Object = {name: "Object"};

var cla:ClassName = new ClassName();
cla.passVariables(obj);

Then you can access references to the variables inside the class.

BBS Signature

None

Gutya

Reply To Post Reply & Quote

Posted at: 6/15/08 10:26 AM

Gutya FAB LEVEL 07

Sign-Up: 11/27/06

Posts: 777

At 6/15/08 10:15 AM, GuyWithHisComp wrote: Then you can access references to the variables inside the class.

Ah, I see. Thanks.


None

Gutya

Reply To Post Reply & Quote

Posted at: 6/15/08 10:34 AM

Gutya FAB LEVEL 07

Sign-Up: 11/27/06

Posts: 777

Another quick question, somewhat related.

How can I go about accessing instances on the stage from inside a class file?

For example if I want the x and y positions of a MC on the stage, and use those inside the class file.

I suck at explaining, hope someone knows what I mean :p

None

johnfn

Reply To Post Reply & Quote

Posted at: 6/15/08 11:22 AM

johnfn LIGHT LEVEL 19

Sign-Up: 08/16/03

Posts: 2,852

Once again, just pass the object you need the properties of to the class when you need it via functions.


None

Gutya

Reply To Post Reply & Quote

Posted at: 6/15/08 11:45 AM

Gutya FAB LEVEL 07

Sign-Up: 11/27/06

Posts: 777

Yeah thanks guys, I realize I've been completley the wrong way about it. It seems so simple now.


All times are Eastern Daylight Time (GMT -4) | Current Time: 04:05 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!