A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [F8] Why aren't I able to dynamically ad movie clips?

  1. #1
    Junior Member
    Join Date
    Apr 2007
    Posts
    8

    [F8] Why aren't I able to dynamically ad movie clips?

    I'm trying to have the hero fire a bullet from his gun. Here's what I have so far, but at the moment it's not working.

    Could someone please give me so help?

    Thanks.

    Here's the function:

    Code:
    function addBullet():Void {
    	if (bullet_array.length>=numBullets) {
    		var tempBullet_mc:MovieClip = this.attachMovie("bullet_id", "bullet"+bullet_array.length+"_mc", this.getNextHighestDepth());
    		this.tempBullet_mc._x = this.hero_mc.arm_mc.gun_mc._x;
    		this.tempBullet_mc._y = this.hero_mc.arm_mc.gun_mc._y;
    	}
    }
    Here's the function call:

    Code:
    this.onMouseUp = function():Void {
    	addBullet();
    };
    Here are the variables:

    Code:
    var bullet_array:Array = new Array();
    var numBullets:Number = 6;

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    it might be due to scope within the function,
    or that bullet_array length does not exceed numBullets (trace for these values)
    this would be my approach -
    PHP Code:
    var bullet_array:Array = new Array();
    var 
    len:Number  bullet_array.length;
    var 
    numBullets:Number 6;
    var 
    TL:MovieClip this;
    var 
    depth:Number this.getNextHighestDepth();

    function 
    addBullet():Void {
    if (
    len>=numBullets) {
    depth++;
    var 
    tempBullet_mc:MovieClip TL.attachMovie("bullet_id""bullet"+depth+"_mc"depth);
    tempBullet_mc._x TL.hero_mc.arm_mc.gun_mc._x;
    tempBullet_mc._y TL.hero_mc.arm_mc.gun_mc._y;
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center