Forum Topic: accessing variables on the main...

(129 views • 6 replies)

This topic is 1 page long.

<< < > >>
None

Disarray-yarrasiD

Reply To Post Reply & Quote

Posted at: 7/30/08 06:15 PM

Disarray-yarrasiD DARK LEVEL 09

Sign-Up: 11/14/04

Posts: 1,474

I was wondering how you access a variable on the main time line from within an AS3 class. It seems to be quite different from AS2 where a simple _root.property_name worked fine.

BBS Signature

None

Disarray-yarrasiD

Reply To Post Reply & Quote

Posted at: 7/30/08 06:52 PM

Disarray-yarrasiD DARK LEVEL 09

Sign-Up: 11/14/04

Posts: 1,474

anyone have any ideas?

If I could, I would be tempted to convert my classes to extensions of the Sprite class, so that I could access the parent property, but since all of my classes are already extending other classes, I don't think that this is an option.

So if anyone knows how to inherit the properties and methods of two classes simultaneously, that would also be a big help.

The main problem is that I want classes to be able to communicate with one another, but I have no idea how this could be accomplished in AS3 now that root. was so dramatically revamped.

BBS Signature

None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 7/31/08 03:09 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,418

Erm have your base class extend Sprite? If you're confused about it chances are it's bad design. -_-

You need to implement interfaces to inherit from multiple classes (but I think you can only implement interfaces in AS).

Since 'root' as a class property is simply typed as DisplayObjectContainer all you need to do is type it to your document class.

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

Disarray-yarrasiD

Reply To Post Reply & Quote

Posted at: 7/31/08 08:11 AM

Disarray-yarrasiD DARK LEVEL 09

Sign-Up: 11/14/04

Posts: 1,474

Since 'root' as a class property is simply typed as DisplayObjectContainer all you need to do is type it to your document class.

sorry, I only started using AS3 this month, could you explain who this is done?

BBS Signature

None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 7/31/08 08:35 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,418

In the DisplayObject class the fields 'parent' and 'root' are typed as DisplayObjectContainer. So when you access 'root' in the view of the static compiler it only has the properties of DisplayObjectContainer even though it's your own class with the properties you want to access. You can use the syntax 'YourClass (yourmovieclip.root).yourproperty' to cast the type to YourClass so you could access the properties in your class. It's ugly because OOP is not designed to be used that way with child objects altering their parents.

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

Disarray-yarrasiD

Reply To Post Reply & Quote

Posted at: 7/31/08 08:57 AM

Disarray-yarrasiD DARK LEVEL 09

Sign-Up: 11/14/04

Posts: 1,474

So if I wanted to access a variable on the main time line from an instance (thing1) of a class (Thing) how exactly would I set it up?

I am really sorry for taking up your time like this, I just ordered the essential action script 3.0 book, so hopefully I won't need to ask so many stupid questions in the future.

BBS Signature

None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 7/31/08 09:29 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,418

YourMainClass (root).yourproperty

You want to get 'yourproperty' from 'root', which obviously has it, but because it has the type of some Flash class it does not allow you to access it. Casting it as shown converts the type to your class so you can safely access it. Get it? Now that you do, don't do that.

If you really don't, maybe stick to AS2.

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


All times are Eastern Standard Time (GMT -5) | Current Time: 06:11 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!