I'm trying to make lots of the same object appear randomly on the screen subject to conditions and keep getting errors? <p>A good friend recommended this site to me, it looks really useful! I'm a bit of a shameless noob at actionscript and after 3 days of tutorials and advice I've hit a brick wall.</p> <p>I've managed to get a sensor attached to an arduino talking to flash using something called AS3glue. it works, when i set up a trace("leaf") for the contition that the sensor reads 0, i get a printout of the word "leaf". however i want the program to make a graphic appear on the screen when this condition is met, not just trace something.</p> <p>I'm trying to get the program to generate a library object called "Enemy" on the screen at a random position each time the conditions are met. It's called enemy because I was following a game tutorial...actually it's a drawing of a leaf.</p> <p>Here's the bit of the code which is causing me problems:</p> <blockquote> <p>var army:Array; var enemy:Enemy;<br> function AvoiderGame() { army = new Array(); var newEnemy = new Enemy( 100, 100 ); army.push( newEnemy ); addChild( newEnemy ); }</p> <p>function timerEvent(event:Event):void { </p> <p>if (a.getAnalogData(0) ==0 &amp;&amp; a.getAnalogData(0) != this.lastposition){</p> <pre><code> trace("leaf"); var randomX:Number = (Math.random() * 200) + 100; var randomY:Number = (Math.random() * 150) + 50; var newEnemy = new Enemy( randomX, randomY); army.push( newEnemy ); addChild( newEnemy ); } else if (a.getAnalogData(0) == 0) { //don't trace anything } &gt;else { </code></pre> <p>//don't trace anything } this.lastposition = a.getAnalogData(0); //afterwards, set the position to be the new lastposition and repeat.</p> <p>}</p> </blockquote> <p>I've imported "import flash.display.MovieClip;"</p> <p>and the code for the Enemy class looks like this:</p> <blockquote> <blockquote> <p>package { import flash.display.MovieClip; public class Enemy extends MovieClip { public function Enemy( startX:Number, startY:Number ) { x = startX; y = startY; } } }</p> </blockquote> </blockquote> <p>Here's my error. I've tried googling, it seems like a pretty general error:</p> <blockquote> <p>TypeError: Error #1009: Cannot access a property or method of a null object reference. at as3glue_program_fla::MainTimeline/timerEvent() at flash.utils::Timer/_timerDispatch() at flash.utils::Timer/tick()</p> </blockquote> <p>I've made sure that the "Enemy" object is exported for AS3.</p> <p>I'm going for something like this when it's programmed in AS2:</p> <blockquote> <p>leafCounter = 0; //set the counter to 0 counter.swapDepths(1000); //puts the counter on top of pretty much anything, unless you make more than 1000 leaves! counter.textbox.text = 0; //shows "0" in the text box in the "counter" movie clip</p> <p>this.onMouseDown = function() { //triggers when the mouse is clicked this.attachMovie("Leaf","Leaf"+leafCounter,leafCounter,{_x:Math.random()*Stage.width,_y:Math.random()*Stage.height,_rotation:Math.random()*360}); //adds a leaf to rthe stage with a random position and random rotation leafCounter++; //adds 1 to the leaf counter counter.textbox.text = leafCounter; //shows that number in the text box }</p> </blockquote> <p>I'm sure it must be a simple error, I can get the logic working when it just traces something on the screen but i can't get it to generate an "enemy"</p> <p>Any help or hints would be really useful! I know this is a bit of a ham-fisted job of altering existing code.</p>