Be a Supporter!

using var from timeline in a class.

  • 351 Views
  • 7 Replies
New Topic Respond to this Topic
benaerens
benaerens
  • Member since: Dec. 17, 2009
  • Offline.
Forum Stats
Member
Level 01
Game Developer
using var from timeline in a class. 2012-11-23 13:52:24 Reply

Hey, I'm in a situation where I need to acces a var (Boolean) that is situated on my main timeline (first frame)

I want to acces it in a bullet class. How would I do this?

I actually tryed this
root.LeanLeft:Boolean

But it doesn't work.

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to using var from timeline in a class. 2012-11-23 13:59:51 Reply

At 11/23/12 01:52 PM, benaerens wrote: Hey, I'm in a situation where I need to acces a var (Boolean) that is situated on my main timeline (first frame)

That raises the question why you use the timeline at all.
It is recommended to use a document class and reduce the code on timelines to a minimum.

I want to acces it in a bullet class. How would I do this?

There are several ways to do this.
The simples way is to pass it to a function of the Bullet class.

Please explain what this boolean variable is and what it should do.
There's no general answer to that question.

I actually tryed this
root.LeanLeft:Boolean

But it doesn't work.

The approach is not good.
You should not go somewhere (root in this case) and try to fetch a variable.
It's possibly not there, somewhere else, etc.

Generally speaking, the things a class needs are passed to it.
Hence more information is required about what you want to achieve.

Psionic3D
Psionic3D
  • Member since: Sep. 19, 2007
  • Offline.
Forum Stats
Member
Level 10
Game Developer
Response to using var from timeline in a class. 2012-12-01 09:56:11 Reply

Probably not good practice but have you tried?

MovieClip(root).variablename

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to using var from timeline in a class. 2012-12-01 11:15:48 Reply

At 12/1/12 09:56 AM, Psionic3D wrote: Probably not good practice but have you tried?

MovieClip(root).variablename

that's is horrible practice, and it's just as bad (actually, slightly worse) as what the OP suggested.
besides, AS3 doesn't have "root" - it has "stage"


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to using var from timeline in a class. 2012-12-02 13:24:01 Reply

At 12/1/12 11:15 AM, egg82 wrote: AS3 doesn't have "root"

it does

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to using var from timeline in a class. 2012-12-02 13:38:36 Reply

At 12/2/12 01:24 PM, milchreis wrote: it does
public class DisplayObject extends EventDispatcher implements IBitmapDrawable
		 
		 /**
		 * For a display object in a loaded SWF file, the root property is the 
		 * top-most display object in the portion of the display list's tree structure represented by that SWF file.
		 * For a Bitmap object representing a loaded image file, the root property is the Bitmap object
		 * itself. For the instance of the main class of the first SWF file loaded, the root property is the 
		 * display object itself. The root property of the Stage object is the Stage object itself. The root  
		 * property is set to null for any display object that has not been added to the display list, unless 
		 * it has been added to a display object container that is off the display list but that is a child of the 
		 * top-most display object in a loaded SWF file.
		 * 
		 *   For example, if you create a new Sprite object by calling the Sprite() constructor method, 
		 * its root property is null until you add it to the display list (or to a display 
		 * object container that is off the display list but that is a child of the top-most display object in a SWF file).For a loaded SWF file, even though the Loader object used to load the file may not be on the display list, 
		 * the top-most display object in the SWF file has its root property set to itself.  The Loader object 
		 * does not have its root property set until it is added as a child of a display object for which the 
		 * root property is set.
		 * @langversion	3.0
		 * @playerversion	Flash 9
		 * @playerversion	Lite 4
		 */
public function get root () : flash.display.DisplayObject;

gotcha.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to using var from timeline in a class. 2012-12-02 13:59:01 Reply

At 12/2/12 01:38 PM, egg82 wrote:
At 12/2/12 01:24 PM, milchreis wrote: it does
public function get root () : flash.display.DisplayObject;

no need to prove my words right, thanks anyway.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to using var from timeline in a class. 2012-12-02 14:02:40 Reply

At 12/2/12 01:59 PM, milchreis wrote: no need to prove my words right, thanks anyway.

I had time, it was easy, and I thought it was interesting enough to share


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature