A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] Help with triggering a response in actionscript

  1. #1
    not'n' wrong with hat'n' sushi iHATEsushi's Avatar
    Join Date
    May 2006
    Location
    Ontario
    Posts
    132

    [F8] Help with triggering a response in actionscript

    Hi there, I have uploaded a cheezy example of what I am trying to achieve with this.

    What I want to happen is when the player clicks the <spacebar> I want it to trigger a particular movie clip. For instance if the player hits the space bar and its below area 2 then I want the area 1 movie clip to play. If the user hits below area 3 then I want movie clip 2 to play etc...

    I created a cheezy animation in each one so that I can see whats going on in each section.

    I am not sure how to go about animating this and using code to coincide with it. Any assistance would be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Sep 2004
    Location
    Columbia, MD
    Posts
    206
    Code:
    var keyListener_obj:Object = new Object();
    keyListener_obj.onKeyDown = function() {
    	switch(Key.getCode())	{
    		case Key.SPACE:
    			powerbar_mc.stop();
    			var frame = powerbar_mc._currentframe;
    			trace(frame);
    			getArea(frame)
    	}
    }
    Key.addListener(keyListener_obj);
    function getArea(frame)	{
    	if (0 < frame && frame < 6)	{ 
    		trace(1);
    		gotoAndStop("area1");
    	}
    	else if (5 < frame && frame < 11)	{
    		trace(2);
    		gotoAndStop("area2");
    	}
    	else if (10 < frame && frame < 16)	{
    		trace(3);
    		gotoAndStop("area3");
    	}
    	else if (15 < frame && frame < 21)	{
    		trace(4);
    		gotoAndStop("area4");
    	}
    }
    I cleaned up a few things in your file, but the above code is what you need.
    Good luck!
    Attached Files Attached Files

  3. #3
    not'n' wrong with hat'n' sushi iHATEsushi's Avatar
    Join Date
    May 2006
    Location
    Ontario
    Posts
    132
    Thanks so much for your reply. I like to learn different code and how things are done because it helps me to make sense of the language. Now the fun part of reading about your code so I can understand it.

    Thanks so much for your assistance.

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