about actionscript 3.0
hi, codes , have 2 things ask, hope can me because beginner use actionscript , need help.
1) want count number of movieclips(in different class) added. is, may have 10 clicks, how many bigfish , smallfish created. function suitable call doing this.
2) have problem on hittest, comes out "no hit" still can see movieclips overlap. , if want modify check whether smallfish overlap bigfish, should do? also, there functions inside movieclip give motion.
stage.addeventlistener(mouseevent.click, addfish);
function addfish(evt:mouseevent):void{
var classnames:array = ["bigfish", "smallfish"];
var classref:class = class(getdefinitionbyname(classnames[math.floor(math.random()*classnames.length)]));
var classinstance:* = new classref();
//classinstance.addeventlistener(event.enter_frame, iskill);
addchild(classinstance);
checkforoverlapf(classinstance);
}
function checkforoverlapf(dobj:displayobject):void{
for(var i:uint=0;i<numchildren;i++)
{
if(getchildat(i)!=dobj)
{
if(dobj.hittestobject(getchildat(i)))
{
trace("hit");
}
}
}trace("not hit");
}
for first part, create 2 arrays, 1 big fish , 1 small fish. each fish gets added, store reference in appropriate array. use class name part of array variable name make storing easier.
with first part done, need check against appropriate array... if it's small fish, test hits using bigfish array.
someone else may have different idea, wait others offer some.
More discussions in Adobe Animate CC - General
adobe
Comments
Post a Comment