Dynamic Movie Clip Creating Help

Hey guys,

For my game, I need it so when you click a button, a certain movie clip gets created at a certain place… thats been done fine… I need it so if you click on another button AFTER the movie clip has been created it will gotoAndStop();…

This is what i’ve done so far…

// Class Imports
import com.cfreps.utils.Global;
// Variables
// Event Listener
SpawnRifleMen.addEventListener(MouseEvent.MOUSE_DOWN, SpawnRifleFunc);
AttackButton.addEventListener(MouseEvent.MOUSE_DOWN, AttackFunc);
// Buttons
function SpawnRifleFunc (e:MouseEvent) 
 {
  SpawnCheck = 1
  var RifleGuy:Rifle = new Rifle();
  RifleGuy.x = 100
  RifleGuy.y = 250
  addChild(RifleGuy);
 }
 
function AttackFunc (e:MouseEvent)
 {
  RifleGuy.gotoAndStop(2);
 }
  

This just gives me "Access of undefined property “RifleGuy”
Which is completely understandable seeing as there is no “RifleGuy” until you press the button…

I’ve tried a few things but I really need some help

Thanks in advance - Kaine