• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Invoking a metod of document class from other class..help

Guest
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

Hello,

I have two classes:

1. DocumentClass
2. GameClass

I would like to be able to call a public method of DocumentClass from GameClass. I don't know how to do that, I tried instantiating an object of DocumentClass within GameClass which simply throws me into an endless loop and after a short while application crashes.

I would appreciate any input on this, please.

Thanks.
TOPICS
ActionScript

Views

304

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

When you create GameClass you can pass in a reference to the document class. So something in your document class might be saying:

var game:GameClass = new GameClass();

if that was:

var game:GameClass = new GameClass(this as MovieClip);

and in GameClass you had:

private var docClass:MovieClip;
public function GameClass(mc:MovieClip){
docClass = mc;
}

then anywhere in GameClass you could say:

docClass.someFunction(params);

and it would call the document class function.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

LATEST
I am not sure if it will totally work and, I believe, some casting is at hand.

The document class instance is passed as a MovieClip. MovieClip is not a dynamic class and doesn't have someFunction method. In order to use this syntax I believe in order for document instance function calls to work one of the following approaches should be taken:

1. Document class is passed as an object (or other dynamic class):
public function GameClass(mc:Object){

2. document class' functions are called - it should be cast to Object. The syntax for calling the method should be something like:
Object(docClass).someFunction(params);

3. (May be too cumbersome from maintanance stand point but very compact) One may want to create an interface with methods of document and pass an interface instance. For example, if an interface is IDocClassInterface the syntax in the game class will be:

public function GameClass(mc:IDocClassInterface):void{


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines