Skip to main content
Known Participant
February 22, 2014
Question

Accessing the stage from a class

  • February 22, 2014
  • 1 reply
  • 1152 views

Hello. I have my character on the stage and the code controlling my character in the document class. In the document class i have a function that dynamically spawns platforms that come down the screen by loading my Platforms.as which has all the code for the random spawning locations and whatnot. How can i create a collision detection between these dynamic platforms and my character?

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
February 22, 2014

If you already have access to the character in the document class, and you create the platforms in the document class, then all you should need to is is continuously execute character.hitTestObject(platforms).  You can place the platforms in an array and loop thru the array to check when a collision occurs.

Known Participant
February 22, 2014

thankyou for your reply. ok so ive put my platform code into my document class but it doesnt work because i had a function in the document class to call them to the stage it went like this

var enemy = new Platforms();

stage.addChildAt(enemy, 0);

that would call the platforms class and reference it as enemy then spawn an enemy every time the function was called. how do i do this within the class?

Ned Murphy
Legend
February 22, 2014

You probably do not need to include the stage reference. 

How does this question relate to the question in your first posting?