Skip to main content
Jon Chambers
Inspiring
November 10, 2016
Answered

Trouble with classes in actionscript. Be gentle, I'm self-taught and new.

  • November 10, 2016
  • 7 replies
  • 321 views

I have an object on the stage, and I have given it the instance name "Jim".

I have a document class named "Jimulator" that frequently refers to "Jim" without any issue.

I have a class script for the class "wall" because I want to program some behaviour for when "Jim" collides with a "wall".

When in "wall", if I copy/paste something that refers to "Jim", I get error 1120.

If I change "Jim" to "Jimulator.Jim" I get error 1119: "Access of possibly undefined property of Jim through a reference with static type Class"

I'm still new to actionscript, and none of this is making any sense to me. Please help.

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer kglad

that would be just as bad and both would significantly decrease efficiency.

you should assemble your walls in an array when you create your level and you should loop (eg, for-loop) through that array using your hitTestObject.  use break in your for-loop to stop checking when if and when a positive hittestobject is generated.

7 replies

kglad
Community Expert
Community Expert
November 10, 2016

opinions will vary but you really shouldn't be referencing jim in the wall class.

the wall class should contain code that references wall and maybe how it interacts with the stage.  honestly, i can't think of anything that would commonly go in a wall class, but maybe you want each wall subclass to explode if it's contacted a certain number of times.  that could go into a wall class.  you would use public variables, public functions and getters and setters to interact with the wall class from outside the wall class.

jim should contain stuff that's needed for jim.  maybe how many lives he starts with when added to the stage and keeping track of how many lives remain etc.  again, you would use public variables, public functions and getters and setters to interact with the jim class from outside the jim class.

you might have a level class that adds jim and various walls to the stage and that contains the code for game play and communicates with jim and the walls via those public variables, functions and getters/setters.

but, if you want to learn this the hard way, you can reference all items on stage from any class that's on stage using a reference to the stage.

Jon Chambers
Inspiring
November 10, 2016

What I was actually trying to write was "if Jim is colliding with any member within the class wall..." but this seemed impossible. I couldn't think of a way of writing the hittest that would allow it.

So instead of adding a condition that checks for a collision with every single wall, what if each wall was constantly checking for Jim?

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
November 11, 2016

that would be just as bad and both would significantly decrease efficiency.

you should assemble your walls in an array when you create your level and you should loop (eg, for-loop) through that array using your hitTestObject.  use break in your for-loop to stop checking when if and when a positive hittestobject is generated.