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

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

Contributor ,
Nov 10, 2016 Nov 10, 2016

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.

TOPICS
ActionScript
263
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

Community Expert , Nov 11, 2016 Nov 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.

Translate
Community Expert ,
Nov 10, 2016 Nov 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.

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
Contributor ,
Nov 10, 2016 Nov 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?

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
Community Expert ,
Nov 11, 2016 Nov 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.

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
Contributor ,
Nov 11, 2016 Nov 11, 2016

So I should run the test in the document class?

I think I'm understanding. So, object classes are for the behaviour of individual objects, but collision detection should always be done in the document class?

Does every wall need a unique instance name? (Not near my computer today, so I can't test this out yet.)

I learned to write actionscript by watching Doug's videos on YouTube, but he stopped just as things were getting interesting, and now I don't know what to watch/read next.

I know too much to read beginner material but not enough to read advanced material. What should I read next?

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
Community Expert ,
Nov 11, 2016 Nov 11, 2016

i wouldn't, but my way is not the only way and others may feel their way is better.

i use the document class to control the 'pages' displayed.  so i would use the document class to create all the pages and add and remove them from the sage.

eg, the first page my be an intro page with a play button, instructions button, a button that links to a high score page etc.

the play button would link to the only pages/classes you're considering in this thread.

i'm suggesting you might want a Game_page1 page/class that would list the levels completed and the levels still not mastered and the levels available to play.  from that page/class you proceed to the Game_page2 page/class where a game level is assembled using your Jim class and using your Wall class(es).

Game_page2 would handle your hittestobject loop.

you would probably have a Game_page3 results page that displays the players results and would have another way to link to the high score page.

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
Contributor ,
Nov 11, 2016 Nov 11, 2016

Keep the advice coming. It's all useful so far.

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
Community Expert ,
Nov 11, 2016 Nov 11, 2016
LATEST

i also like to use a Data class that is a singleton or static class that uses a sharedobject to store data (eg, high scores, levels achieved etc).  that class (and therefore the data) is available to all other classes in project.

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