Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple movieclips all go to the same spot; What am i doing wrong?
    primarykey
    data
    text
    <p>So I'm trying to shoot multiple bullets out of my body and it all works except I have an odd problem of just one bullet showing up and updating to set position for the new ones. I have a move able player thats supposed to shoot and I test this code by moving the player and shooting. Im taking it step by step in creating this.</p> <p>The result of tracing the bulletContainer counts correctly in that its telling me that movieclips ARE being added to the stage; I Just know it comes down to some kind of logic that im forgetting.</p> <p><strong>Here's My Code</strong> (The Bullet it self is a class)</p> <p><strong>UPDATE*</strong> Everything in this code works fine except for I stated earlier some code seems reduntned because I've resorted to a different approaches. </p> <p><strong>BulletGod Class:</strong></p> <pre><code>public class bulletGod extends MovieClip{ //Register Variables //~Global var globalPath = "http://127.0.0.1/fleshvirusv3/serverside/" //~MovieCLips var newBullet:bulletClass = new bulletClass(); //~Boolean var loadingBulletInProgress:Number = 0; var shootingWeapon:Number = 0; //~Timers var fireBulletsInterval = setInterval(fireBullets, 1); var bulletFireEvent; //~Arrays var bulletArray:Array = new Array(); var bulletType:Array = new Array(); var bulletContainer:Array = new Array(); //~Networking var netBulletRequest:URLRequest = new URLRequest(globalPath+"bullets.php"); var netBulletVariables:URLVariables = new URLVariables(); var netBulletLoader:URLLoader = new URLLoader(); //~Bullet Image Loader var mLoader:Loader = new Loader(); var mRequest:URLRequest = new URLRequest(); public function bulletGod() { //Load every bullet for every gun //Compile data to be requested netBulletVariables.act = "loadBullets" netBulletRequest.method = URLRequestMethod.POST netBulletRequest.data = netBulletVariables; netBulletLoader.dataFormat = URLLoaderDataFormat.VARIABLES; netBulletLoader.addEventListener(Event.COMPLETE, getBulletImages); netBulletLoader.load(netBulletRequest); } private function getBulletImages(bulletImageData:Event){ //Request every bullet URL image //Set vars var bulletData = bulletImageData.target.data; //Load images for(var i:Number = 0; i &lt; bulletData.numBullets; i++){ bulletArray.push(bulletData["id"+i.toString()]); bulletType.push(bulletData["bullet"+i.toString()]); //trace(bulletData["id"+i]+"-"+bulletData["bullet"+i]); } //All the arrays have been set start firing the image loader/replacer var imageLoaderInterval = setInterval(imageReplacer, 10); } private function imageReplacer(){ //Check to see which image needs replacing if(!loadingBulletInProgress){ //Begin loading the next image //Search for the next "String" in the bulletType:Array, and replace it with an image for(var i:Number = 0; i &lt; bulletType.length; i++){ if(getQualifiedClassName(bulletType[i]) == "String"){ //Load this image mRequest = new URLRequest(globalPath+"ammo/"+bulletType[i]); mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImage); mLoader.load(mRequest); //Stop imageReplacer() while we load image loadingBulletInProgress = 1; //Stop this for() loop while we load image i = 999; } } } } private function loadImage(BlackHole:Event){ //Image has loaded; find which array slot it needs to go into for(var i:Number = 0; i &lt;= bulletType.length; i++){ if(getQualifiedClassName(bulletType[i]) == "String"){ //We found which array type it belongs to; now replace the text/url location with the actual image data var tmpNewBullet:MovieClip = new MovieClip; tmpNewBullet.addChild(mLoader); //Add image to array bulletType[i] = tmpNewBullet; //Restart loadingBullets if there are more left loadingBulletInProgress = 0; //Stop for() loop i = 999; } } } //############################################################################################################################################### private function fireBullets(){ //If player is holding down mouse; Fire weapon at rate of fire. if(shootingWeapon &gt;= 1){ if(bulletFireEvent == null){ //Start shooting bullets bulletFireEvent = setInterval(allowShooting, 500); } } if(shootingWeapon == 0){ //The user is not shooting so stop all bullets from firing if(bulletFireEvent != null){ //Strop firing bullets clearInterval(bulletFireEvent); bulletFireEvent = null } } } private function allowShooting(){ //This function actually adds the bullets on screen //Search for correct bullet/ammo image to attach var bulletId:Number = 0; for(var i:Number = 0; i &lt; bulletArray.length; i++){ if(bulletArray[i] == shootingWeapon){ //Bullet found bulletId = i; //End For() loop i = 999; } } //Create new bullet //Create Tmp Bullet var tmpBulletId:MovieClip = new MovieClip tmpBulletId.addChild(newBullet); tmpBulletId.addChild(bulletType[bulletId]); //Add To Stage addChild(tmpBulletId) bulletContainer.push(tmpBulletId); //Add to array of bullets //Orientate this bullet from players body var bulletTmpId:Number = bulletContainer.length bulletTmpId--; bulletContainer[bulletTmpId].x = Object(root).localSurvivor.x bulletContainer[bulletTmpId].y = Object(root).localSurvivor.y //addChild(bulletContainer[bulletTmpId]); } //_______________EXTERNAL EVENTS_______________________ public function fireBullet(weaponId:Number){ shootingWeapon = weaponId; } public function stopFireBullets(){ shootingWeapon = 0; } } } </code></pre> <p><strong>BulletClass:</strong></p> <pre><code>package com{ import flash.display.* import flash.utils.* import flash.net.* import flash.events.* public class bulletClass extends MovieClip { public var damage:Number = 0; public function bulletClass() { //SOME MOVEMENT CODE HERE } public function addAvatar(Obj:MovieClip){ this.addChild(Obj); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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