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

Problem with classes and oop basics.

Explorer ,
Jun 12, 2013 Jun 12, 2013

I got a main class called "controll class":

There I addChild a btn to the stage and create a listener for click on that btn.

When clicked the function animated the curretn clip on the stage and moves it out and addChild another movieclip

called Levels_BG

Levels_BG contains at attached and controled but its onwl class: Levels_BG

Which creates a number of 'boxs' on the stage that can be clicked to select a level.

I am tryin to achieve this:

a level box is clicked in the Levels_BG and I need to pass this variable to another class.

Any help appriciated. sry if this is confussing.

Cheers Pavel

swf here:

http://www.2shared.com/document/pO8IIf4x/NumberGame.html

TOPICS
ActionScript
640
Translate
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

correct answers 1 Correct answer

Explorer , Jun 13, 2013 Jun 13, 2013

Managed to get it working found htis brilliant guide:

http://stackoverflow.com/questions/11083843/as3-call-function-from-one-class-to-another

I changed my function in control_Class:

static public function startlevel ():void

                    {

                              trace("from that class to this one")

                    }

control_Class.startlevel();

thx for the help.

pav

Translate
Community Expert ,
Jun 12, 2013 Jun 12, 2013

there are a number of ways to communicate among classes.  deciding which is best depends on some specifics.

for example, is there a simple relationship between Levels_BG and your other class?  eg, did your other class created the Levels_BG instance?

is there no simple relationship?  for example, i often use  Data class contains information that needs to be shared among several other classes like a setup class where a user selects parameters and those parameters are used in other classes to control the app.  in that situation, using a singleton Data class or static Data class makes sense.

i've never used more than one static/singleton class per app so most communication is not done via this global-type class.  some people think static/singleton classes should never be used.  but, i think, those are mostly teacher-types, not doers.

Translate
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
Explorer ,
Jun 13, 2013 Jun 13, 2013

Thx for the reply.

The relation ship between the 2 classes is that controll class addChild amovieclip to the stage that is attached to Levels_BG class.

Was think about using a static variable - but I need to run a function in Levels_BG that runs a function in controll class 

which essentially will removeChild the movie clip that's controlled by Levels_BG this is what I am trying my am getting an error:

in controll class:

public function startlevel ():void

                    {

                                   trace("from that class to this one")

                    }

in Levels_BG:

private static var controlCall:control_Class = new control_Class

controlCall.startlevel();

But this gives me this error:

Error #1009: Cannot access a property or method of a null object reference.

          at control_Class()

          at Levels_BG$cinit()

          at global$init()

Hope you can help.

thx pavel

ps. ' those are mostly teacher-types, not doers' - brilliant


Translate
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
Explorer ,
Jun 13, 2013 Jun 13, 2013
LATEST

Managed to get it working found htis brilliant guide:

http://stackoverflow.com/questions/11083843/as3-call-function-from-one-class-to-another

I changed my function in control_Class:

static public function startlevel ():void

                    {

                              trace("from that class to this one")

                    }

control_Class.startlevel();

thx for the help.

pav

Translate
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