A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: passing variable value between two movie clips

  1. #1
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378

    passing variable value between two movie clips

    Okay I'm pretty much at the end of my rope here, so I need some help. I've searched through over 6000 threads for the Flash MX board here on the site and finally gave up. So anyhow...

    In the movieclip called Flik, instance name "wf":
    Code:
    onClipEvent (load) {
    	//bullet fire
    	_root.bullet._visible = false;
    	bulletCounter = 1;
    	//initial Flik mc
    	moveSpeed = 5;
    	this.attachMovie("walk_down", "wd", 1);
    	clipToDelete = "wd";
    }
    onClipEvent (enterFrame) {
    	//for Flik to walk
    	if (Key.isDown(97)) {
    		dPad = 1;
    		//walk down left
    		if (clipToDelete != "wdl") {
    			//test if Flik is already walking in this direction
    			removeMovieClip(clipToDelete);
    			//If not, remove the current mc
    			this.attachMovie("walk_downleft", "wdl", 0);
    			//attach the clip to walk in direction pressed
    			clipToDelete = "wdl";
    			//reset the varible clipToDelete for the next test
    		} else {
    			this._y += moveSpeed;
    		}
    		this._x -= moveSpeed;
    		wdl.nextFrame();
    	} else if (Key.isDown(98)) {
    		dPad = 2;
    		//walk down
    		if (clipToDelete != "wd") {
    			removeMovieClip(clipToDelete);
    			this.attachMovie("walk_down", "wd", 0);
    			clipToDelete = "wd";
    		} else {
    			this._y += moveSpeed;
    		}
    		wd.nextFrame();
    	} else if (Key.isDown(99)) {
    		dPad = 3;
    ... all the way to dPad=9 and then:
    //for bullet fire
    	if (Key.isDown(Key.CONTROL)) {
    		bulletCounter++;
    		_root.bullet.duplicateMovieClip("bullet"+bulletCounter, bulletCounter);
    		_root["bullet"+bulletCounter]._visible = true;
    			if (bulletCounter>25) {
    				bulletCounter=1
    			}
    	}
    note the dPad = 1, 2, and 3 in bold...

    And in my movieclip called bulletfire, instance name "bullet":
    Code:
    onClipEvent (load) {
    	bulletSpeed = 35;
    	this._y = _root.wf._y;
    	this._x = _root.wf._x;
    }
    onClipEvent (enterFrame) {
    Ref = _root.wf.dPad;	
    		if (Ref=1) {
    		this._x -= bulletSpeed;
    		this._y += bulletSpeed;
    	} else if (Ref=2) {
    		this._y += bulletSpeed;
    	} else if (Ref=3) {
    		this._x += bulletSpeed;
    		this._y += bulletSpeed;
    	}
    ...
    Ok, so here's what happens... I have eight different movie clips for a walk animation, capable of letting the character walk in eight different directions (1-4 & 6-9 on the Num Pad). What should happen is bullet calls the dPad variable in wf and depending on what number it is, increments the x & y of the bullet so that when you face left, you shoot left, face right, shoot right, etc.

    If it isn't clear enough just ask and I'll try to be more clear... sorry if it is I've been trying to settle this problem for almost 7 hours now...

    *Edit* I originally wanted to use the clipToDelete variable you see in the wf mc but since I was having problems I changed it. If it is possible to use the string for each direction, let me know because it would be one less variable and a lot less code.
    Last edited by ImprisonedPride; 04-27-2006 at 09:10 PM.

  2. #2
    Hey Timmy!!! walsher's Avatar
    Join Date
    Jan 2005
    Location
    Latrobe, PA
    Posts
    1,899
    Howdy, I recall answering a question similar to yours. Instead of changing the direction of your bullet on the enterframe, you should change it to animation in your bullet. Attached is an example I made to show what I mean. It's also in Flash MX 2004.
    Attached Files Attached Files

  3. #3
    Senile member! :)
    Join Date
    Dec 2001
    Location
    Saunaswamp (transl)
    Posts
    2,296
    You have done the classic misstakes of using only a single = when testing for equality while it should be double ( == ).

    Code:
    if (Ref==1) {
    	this._x -= bulletSpeed;
    	this._y += bulletSpeed;
    } else if (Ref == 2) {
    	this._y += bulletSpeed;
    } else if (Ref==3) {
    	this._x += bulletSpeed;
    	this._y += bulletSpeed;
    }
    /Mirandir

  4. #4
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    Thanks Mirandir, it worked your way. I couldn't get the FLA to open though. Anyhow, a new problem has arisen! Now that it actually works, it doesn't do what I want it to do with the bullets. You can't see it here, but there is a check just after the onClipEvent(enterFrame) that deletes the mc of the duplicated bullet mc if it's off screen. The this._x inside of each duplicated mc creates a problem that allows me to change the bullets direction half way through firing just by changing the direction of the ship! Case in point; if I start off and fire five or six rounds to the left, and as they approach the left stage edge (where they would normally be deleted), I turn and face the right, the bullets stop dead and start moving to the right. I need each duplicated bullet mc to act independently but I believe the problem is coming from how I'm pathing the clip when I tell it to change it's x and y value? Thanks in advance once again.

    Marc

  5. #5
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    Nevermind, I fixed it. The problem was each mc was grabbing the Ref value every cycle. I put it into the onClipEvent(load) and that fixed it.

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