flash - Adding multiple movieclip symbols dynamically with actionscript: how to? -


i have movieclip symbol named "main", trying use empty base add other movieclips to.

i have 2 additional movieclip symbols, named "a" , "b", of whom both have .png images in them.

i trying have both movieclip symbols "a" , "b" show dynamically when actionscript tells them to. in following code, movieclip "a" shows fine, while movieclip "b" not.

package  {  import flash.display.movieclip; import flash.events.mouseevent;  public class main extends movieclip {      var a:symbol_a;     var b:symbol_b;      public function main() {         = new symbol_a();         addchild(a);          a.addeventlistener(mouseevent.mouse_up, mouseup);     }      function mouseup(event:mouseevent):void     {         b = new symbol_b();         addchild(b);     } } 

}

i must missing something!

i have read several things addchild, not sure how of applies me. post here attempt focus search information adding movieclips dynamically, appreciate has advice on matter.

edit: no longer believe there wrong code. silly typo giving me problems. not sure whether delete question, mark answered, or leave be!

first of check if symbol_a clickable. add trace("mouse triggered!") in mouseup method. maybe display object lays on main, can't receive mouseevent. also, if both symbols include same image, not see difference, try add symbol_b in position.

here example you, every time click square (display object image inside, in case) added 1 more object @ random position:

package {      import flash.display.bitmap;     import flash.display.bitmapdata;     import flash.display.sprite;     import flash.display.stagealign;     import flash.display.stagescalemode;     import flash.events.event;     import flash.events.mouseevent;      public class stackoverflow extends sprite {          public function stackoverflow() {             addeventlistener(event.added_to_stage, onadded);         }          private function setup():void {             var simplemc:sprite = createwithimage(100, 100);             addchild(simplemc);             simplemc.addeventlistener(mouseevent.mouse_down, ondown);         }          private function createwithimage(width:int, height:int):sprite {             var result:sprite = new sprite();             var bitmapdata:bitmapdata = new bitmapdata(width, height, false, math.random() * 0xffffff);              result.addchild(new bitmap(bitmapdata));             return result;         }          private function ondown(e:mouseevent):void {             var addonemore: sprite = createwithimage(100, 100);             //place object under in list             addchildat(addonemore, 0);             addonemore.x = stage.stagewidth * math.random();             addonemore.y = stage.stageheight * math.random();         }          private function onadded(e:event):void {             removeeventlistener(event.added_to_stage, onadded);              stage.align = stagealign.top_left;             stage.scalemode = stagescalemode.no_scale;              setup();         }     } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -