Note that there are some explanatory texts on larger screens.

plurals
  1. POaddCircle to existing movieclip, using name of clip from an array
    text
    copied!<p>I am currently building a project where I have a map with a number of ship and aircraft. What I am trying to achieve is to check the Line of Sight distance between them. I have set up a LOS Calculator which checks the height of one platform and the height of a second platform then gives a response. That works fine.</p> <p>I then wanted to addCircle based on the result from this calculator. So if the result was 10 it would draw a circle 10cm in radius. If the result was 100 then it would draw it at 100, you get the picture. This works.</p> <p>My problem now is that I need to be able to click on one platform either before or after I have made the calculation and the .addCircle be added to that movieClip. I have set up an array to store the movieclips instance names and traced that. I have added a field on stage so that you can click on a platform and it will recognise the platform clicked. I am just lost as to how to get the circle into the movieClip that has been clicked.</p> <p>I am very new to AS3 so this is starting todo my head in. Any help would be greatly appreciated.</p> <p>The code I have is attached below. I hope I have inserted this properly. Thanks again</p> <pre><code>import flash.events.MouseEvent; import flash.display.MovieClip; stage.focus=ht1; // creation of array containing movieclips and code that adds the clicked movieclip to Array-platformClicked var platformArray:Array = [arunta_mc, f15_mc]; var platformClicked = []; var selectedPlatform:MovieClip = new MovieClip(); for(var i:int = 0; i &lt; platformArray.length; i++) { platformArray[i].buttonMode = true; platformArray[i].addEventListener(MouseEvent.CLICK, item_onClick); } function item_onClick(event:MouseEvent):void { var selectedPlatformArray:Array = platformArray.filter(checkName); selectedPlatform = selectedPlatformArray[0]; myText.text = event.currentTarget.name + " was clicked"; var platformClicked = String(event.currentTarget.name); trace(platformClicked); } function checkName(item:MovieClip, index:int, array:Array):Boolean { return(item.name == platformClicked); } //setup of LOS Calculator code var counter:Number=1; operator_txt.text = "+"; ht1.restrict="-0123456789."; ht2.restrict="-0123456789."; var myresult:Number; var test = []; //start of code when equal button is pressed equal_btn.addEventListener(MouseEvent.CLICK, equalhandler); var newCircle:Shape = new Shape();//defines circle to be drawn function equalhandler(event:MouseEvent):void{ newCircle.graphics.lineStyle(1, 0x000000); newCircle.graphics.beginFill(0x435632); newCircle.alpha = .1; //start of result code result_txt.text = String(int((1.23*(Math.sqrt(Number(parseFloat(ht1.text)+parseFloat(ht2.text)+"")))))); var test = String(int((1.23*(Math.sqrt(Number(parseFloat(ht1.text)+parseFloat(ht2.text)+"")))))); trace(test); //end of result code newCircle.graphics.drawCircle(0,0,test);//add circle based on LOS calculation newCircle.graphics.endFill(); //var selectedPlatform:MovieClip = selectedPlatformArray[0]; selectedPlatform.addChild(newCircle);//this is where I need to add newCircle to the movieClip that is clicked trace(selectedPlatform); //trace(platformClicked); } //start of code for the clear button clear_btn.addEventListener(MouseEvent.CLICK, clearhandler); function clearhandler(event:MouseEvent):void{ ht1.text=ht2.text=result_txt.text=""; removeChild(newCircle); var test = []; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload