The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsOkay, I've got a problem calling methods or functions or whatever their called for different files. Hypothetical Code below to explain problem.
main file.
[code]
package{
public class whatev extends MovieClip{
public function whatev(){
var s:animal = new animal()
addChild(s)
s.addEventListener(Event.ENTER_FRAME, collisionCheck)
}
public function collisionCheck(evt:Event){
//Does stuff like calls method from animal class called morestufftodo...how?
}
}
}
[/code]
animal file
[code]
package {
public class animal extends MovieClip{
public function animal(){
//does stuff
}
public function morestufftodo(){
//I want this to fire upon being called by main class in event of a collision
}
}
}
[/code]
Hope you all can help
you don't call these,
these are not methods, but classes.
ie: AS File, ActonScript File, Class File
you import them.
import packageName.*;
import packageName.className; He made his point in the code.
There are three ways of doing this, some complicated, some not. I will list them all in a random order fo you to pick the one you need.
The first one is to dispatch an event of your own if a collision is detected. Pro: the sending class doesn't need to know who is listening. pro: it works if you want more than one thing to run at a collision. Con: if you want any special parameters, you will need to write a custom event object class and use that.
The second one is to have a reference to the class instance that has the method. Pro: it's fairly simple calling syntax. Pro: you might have a need for the reference for other purposes anyway. Con: It ties the code to just one type.
The third one is to use Function objects. Con: it's fairly advanced. Pro: You can call those anonymous inline functions. Pro: it's easy to swap the function to call. Pro: in as 3 it works fine with methods. Con: It doesn't work fine with methods in as 2, they forget their objects.
Happy brain overload due to my overkill response. But I take pride in leaving nothing out. I inform, you decide.
Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.