2 Replies - 6945 Views - Last Post: 16 January 2010 - 06:40 PM

#1 mary_fisher  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 26-May 09

How to reference to instance of document class

Posted 04 June 2009 - 12:41 PM

Hey,

Ok, this really will stress my english, so bear with me.

I have a problem calling a method of the document class from any other class. Since I don't know the "name" of this instance I can not call it directly. AS3 does not give it a name by which I can call it, nor does it allow me, as far as I know, to name it myself (which then would maybe make it possible to write it into a global variable).

I tried adding a 'this' as parameter when I would create an instance of another class inside the document class. Then I would save it in a class property of the type 'Object'. But that caused an TypeError (namely #1010) later on.

Next I tried the aquivalent of the public static var by stating my document class method simply 'public static function'! But - as I just read and experienced - then I get a problem calling other methods from within THIS method.

There's even a problem when I work with instances of display classes, that I added as child to the document class instance. Inside this display class I tried refering to the parent instance as - well, parent, obviously, but that did not work either. That only works with event.target.parent somehow. But for that I need an event.


So is this a conceptual error on my side - or is it AS3 and I just have to live with it and try working around it? I usually can, but this time, I need to call back to the document class instance because I have to wait for an xml-file to load!

Is This A Good Question/Topic? 0
  • +

Replies To: How to reference to instance of document class

#2 UnknownFury  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 17
  • Joined: 09-March 09

Re: How to reference to instance of document class

Posted 09 June 2009 - 05:12 AM

I think I understand you correctly.. Basically you want to reference the document class from within another class? You can pass it over in the constructor function and refer to that, like so:

package
{
	
	import DocClass;
	
	public class MyClass
	{
		
		var doc:DocClass;
		
		function MyClass(newDoc)
		{
			doc = newDoc;
		}
	}
}


Where DocClass is your document class. Then you can refer to the document class via the doc variable.
Was This Post Helpful? 1

#3 mika_mikeland  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-January 10

Re: How to reference to instance of document class

Posted 16 January 2010 - 06:40 PM

Hi there!

Check at my new tutorial and download its source of a OOP Flash website using AS3 external classes.

No more code in the timeline!!!

Check here: http://www.mikeland....tform/index.swf

Hope you enjoy!!

Mike

This post has been edited by mika_mikeland: 16 January 2010 - 06:41 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1