actionscript 3 - adding a object to another object in as3 -



actionscript 3 - adding a object to another object in as3 -

ok have character on screen , when moves photographic camera follows(thanks manifest222 on youtube) have wall player cant go through. have boxes adding stage want box adds onto object hers code.

package { import flash.display.sprite; import flash.display.movieclip; import flash.events.event; import flash.events.mouseevent; import flash.text.textfield; import flash.display.stage; public class main extends movieclip { // player public var characterendmc:movieclip = new charendmc(); public var arrayofbarrier:array = new array(); //box private var boxamount:number=0; private var boxlimit:number=20; private var _root:object; //$txt public var money:int=0; public var gold:int=0; public var my_scrollbar:makescrollbar; //$$ public var testnumber:number=1; //enemy1 private var e01amount:number=0; private var e01limit:number=2; public function main() { $box.click$.move$.buttonmode=true; $box.click$.clickmini$.buttonmode=true; backgroundpic.visible = false; character_mc["charangle"]=0; character_mc["movex"]=0; character_mc["movey"]=0; character_mc["walkspeed"]=5; stage.addeventlistener(mouseevent.click, charmove); //box add together listener addeventlistener(event.enter_frame, eframe); //moneybox $box.click$.move$.addeventlistener(mouseevent.mouse_down, startmoving$); $box.click$.move$.addeventlistener(mouseevent.mouse_up, stopmoving$); $box.click$.clickmini$.addeventlistener(mouseevent.click, c$mini); my_scrollbar=new makescrollbar(scroll_mc,scroll_text); } public function charloop(event:event) { if (character_mc.hittestpoint(character_mc["charend"].x,character_mc["charend"].y,true)) { character_mc["movex"]=0; character_mc["movey"]=0; this.removechild(character_mc["charend"]); character_mc.removeeventlistener(event.enter_frame, charloop); } (var j:int = 0; j < arrayofbarrier.length; j++) { if (character_mc.hittestobject(arrayofbarrier[j])) { character_mc.x-=character_mc["movex"]; character_mc.y-=character_mc["movey"]; character_mc["movex"]=0; character_mc["movey"]=0; this.removechild(character_mc["charend"]); character_mc.removeeventlistener(event.enter_frame, charloop); } } (var i:int = 0; < this.numchildren; i++) { this.getchildat(i).x-=character_mc["movex"]; this.getchildat(i).y-=character_mc["movey"]; } character_mc.x+=character_mc["movex"]+.05; character_mc.y+=character_mc["movey"]+.05; } public function lookatmouse() { var charactermc:movieclip=character_mc; charactermc["charangle"] = math.atan2(this.mousey - charactermc.y, this.mousex - charactermc.x) / (math.pi / 180); charactermc.rotation=charactermc["charangle"]; } public function charmove(event:mouseevent) { lookatmouse(); this.addchild(characterendmc); characterendmc.x=this.mousex; characterendmc.y=this.mousey; character_mc["charend"]=characterendmc; character_mc["charend"].visible = false; character_mc["movex"]=math.cos(character_mc["charangle"]*math.pi/180)*character_mc["walkspeed"]; character_mc["movey"]=math.sin(character_mc["charangle"]*math.pi/180)*character_mc["walkspeed"]; character_mc.addeventlistener(event.enter_frame, charloop); } //boxadding private function eframe(event:event):void { if (boxamount<boxlimit) { boxamount++; var _box:box=new box ; _box.addeventlistener(mouseevent.click,boxclick); _box.buttonmode=true; _box.y=math.random()* backgroundpic.height; _box.x=math.random()* backgroundpic.width; addchild(_box); } if (e01amount<e01limit) { e01amount++; var enemy1: enemy01=new enemy01 ; enemy1.addeventlistener(mouseevent.click, en01click); enemy1.buttonmode=true; enemy1.y=math.random()*stage.stageheight; enemy1.x=math.random()*stage.stagewidth; addchild(enemy1); } } public function boxclick(event:mouseevent):void { var _box:box=event.currenttarget box; logtxt.appendtext("you collected " + testnumber + " boxes" + "\n" ); character_mc["movex"] = _box.y + 40 + (character_mc.height / 2); character_mc["movey"]=_box.x; logtxt.scrollv=logtxt.maxscrollv; var randval$:number=math.random(); if (randval$>=0.49) { money+=100; } else if (randval$ <= 0.50 && randval$ >= 0.15) { money+=200; } else if (randval$ <= 0.14 && randval$ >= 0.02) { gold+=10; } else if (randval$ == 0.01) { money+=200; gold+=20; } testnumber++; boxamount--; $box.box$in.box$insins.moneytxt.text=string(money); $box.box$in.box$insins.goldtxt.text=string(gold); removechild(_box); } private function startmoving$(event:mouseevent):void { $box.startdrag(); } private function stopmoving$(event:mouseevent):void { $box.stopdrag(); } private function c$mini(event:mouseevent):void { $box.click$.move$.visible=false; $box.box$in.visible=false; $box.y=200; $box.x=100; $box.click$.clickmini$.addeventlistener(mouseevent.click, reclickbox$); $box.click$.clickmini$.removeeventlistener(mouseevent.click, c$mini); } private function reclickbox$(event:mouseevent):void { $box.click$.clickmini$.addeventlistener(mouseevent.click, c$mini); $box.click$.clickmini$.removeeventlistener(mouseevent.click, reclickbox$); $box.y=70; $box.x=250; $box.click$.move$.visible=true; $box.box$in.visible=true; } public function scroll_text( n:number ) { logtxt.scrollv = math.round( ( logtxt.maxscrollv - 1 ) * n ) + 1; } public function en01click (event:mouseevent){ } } }

that's:

var _box:box = new box(); receivingdisplayobjectinstancename.addchild(_box);

actionscript-3 flash-cs4

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -