School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,464 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,654 people online right now. Registration is fast and FREE... Join Now!




How to reference to instance of document class

 

How to reference to instance of document class, (or simple callback)

mary_fisher

4 Jun, 2009 - 11:41 AM
Post #1

New D.I.C Head
*

Joined: 26 May, 2009
Posts: 3

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!

User is offlineProfile CardPM
+Quote Post


UnknownFury

RE: How To Reference To Instance Of Document Class

9 Jun, 2009 - 04:12 AM
Post #2

New D.I.C Head
*

Joined: 9 Mar, 2009
Posts: 14



Thanked: 4 times
My Contributions
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:

CODE
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.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:25AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month