Be a Supporter!

Actionscript Help

  • 223 Views
  • 2 Replies
New Topic Respond to this Topic
toadmancody538
toadmancody538
  • Member since: May. 15, 2008
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Actionscript Help 2009-01-25 10:50:06 Reply

I have a code that will send one symbol from the left screen to the right screen. How do I get it to send more than one? Here's the code:

enemyOut = 0;
_root.onEnterFrame=function(){
if(enemyOut == 0){
duplicateMovieClip(_root.enemy, "enemyNew", 10);
enemyOut = 1;
}
}

I have to tell you something. I have canc-ZOMG A SHINY NEW PENNEY!

Best Webhosting EVER!!!

Deathcon7
Deathcon7
  • Member since: Oct. 1, 2003
  • Offline.
Forum Stats
Member
Level 21
Writer
Response to Actionscript Help 2009-01-25 11:00:14 Reply

You're going to have to think up a better system than that. What ends are you trying to meet?

To give you a tip though, using the attachMovie is a lot easier in some cases, and more effective, than the duplicateMovieClip() function. Use the built in documentation to learn more about attachMovie(). I bet it'll really help you.

abseeley
abseeley
  • Member since: Jul. 10, 2005
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Actionscript Help 2009-01-25 11:26:45 Reply

Um I have to agree with ^ thats a very very poor system for moving something across the screen. Im assuming because you used enemy your making some kind of side scrolling enemies that move across the screen then disappear

The non-oop way:
var myEnemyArray:Array = new Array(); //create our array for enemies
//right here is where you choose how often enemy spawn ill leave that to you
//so below will spawn an enemy and place him on the stage and push him onto the array
var mcEnemy:MovieClip = new mcEnemyLib(); //mcEnemyLib is what you called it int he library (linkage)
mcEnemy.x = 600; ///puts him over on the right
mcEnemy.y = 300; ///puts him at 300 down can easily be replaced with math.rand() * stage hieght to get a random place
addChild(mcEnemy);
myEnemyArray.push(mcEnemy);

//now we have all the enemies in an array in a separate function that is updated every frame (onEnterFrame) we do this
if(myEnemyArray.length > 0){ //make sure there is an enemy or we get an error
for(var i:Number = 0; i < myEnemyArray.length - 1; ++ i){ //this will loop through all the enemies in our array
myEnemyArray[i].x -= 10; //will go through each enemy and move him 10 left
}} ///close what we opened

The oop way:
im assuming if you can do oop then i dont need to write out the code, just make an object that extends your enemy movie clip and add an enter frame listener that moves itself however much in whatever direction, then removes itself automatically if shot, to far off screen yada yada.
Hope that helped (its in AS3 by the way cause you didnt specify)