PDA

View Full Version : How would I make this bit of code?



ninja
April 13th, 2007, 01:04 AM
LOL I really suck with actionscipt.



this question is for ANYONE reading this who knows how to answer it: I want to make a code command similar to this (For my flash game):

If “Beat Area” (Button inside a movieclip) is clicked,
Play “PerfectCombo” (Movie clip measuring combo)

(NOTE: "Perfect combo" is a movieclip with frame 1 being the number "1", frame 2 being "2" and so on. Each frame has a stop command, so playing it would just bring it to the next frame)

Dwight
April 13th, 2007, 03:04 AM
ok I don't really understand what you mean with the "perfect combo" Movieclip. Does it have to play a random frame or what?

Anyways, for the "Beat Area" use the following:

1) Give the "Beat Area" button an instance name like "beatarea"
2) Give the "Perfect Combo" movieclip an instance name like "perfectcombo"
3) Type the following code in the actions window:

ActionScript Code:

beatarea.onRelease = function() {
perfectcombo.gotoAndPlay(framenumber you want it to play);
}





This should work...

ninja
April 13th, 2007, 09:56 PM
ok I don't really understand what you mean with the "perfect combo" Movieclip. Does it have to play a random frame or what?

Anyways, for the "Beat Area" use the following:

1) Give the "Beat Area" button an instance name like "beatarea"
2) Give the "Perfect Combo" movieclip an instance name like "perfectcombo"
3) Type the following code in the actions window:

ActionScript Code:


beatarea.onRelease = function() {


perfectcombo.gotoAndPlay(framenumber you want it to play);
}





This should work...
uhh...sorry, that doesnt work. I am just about going crazy from trying to make this game...I was working for hours with that code you gave me and I cant get ANYTHING out of it.

hybrid101
April 14th, 2007, 02:49 AM
put this on the button itself

on(release){
_root.perfectCombo.nextFrame();
}

ninja
April 14th, 2007, 03:29 AM
nnnnooooo...That one doesn't work either...or maybe im using it wrong, but Im almost positive Im doing it right...

These kinds of things is why actionscript bothers me...

pingnak
April 14th, 2007, 12:43 PM
It's not 'actionscript' at fault, per se. Actionscript its self is no worse than the other dozens of half-baked java-like scripting languages out there.

I blame the crappy Flash UI and the design for how they hooked the code up to their player. It's that whole 'WYSIWYG' thing they seem to have borrowed badly from Microsoft's Visual BASIC. There's always one more setting buried in one more dialog to make something work, and that model of 'scattering' your code to the nine winds in little 'hooks' doesn't help matters at all, nor does their lousy code editor and debugger, and the way you edit a 'class.as' file and it doesn't save it when you build. All minor little irritations.

That at least was my experience learning to use it.

As for your current problems, I'd abandon the UI controls and set up 'hot spots' on the stage that I managed myself. Cut out ALL the middle-men. Either point-in-rect with the mouse x,y or 'hitTest' on something on the stage with the mouse pointer when a 'mouse down' event happens.

If you still can't control-shift-delete and get your breakpoints to hit in the debugger, you have other issues.


BTW, would this be a nice point to rant about Version Control? I think it would. USE IT.

ninja
April 14th, 2007, 03:01 PM
It's not 'actionscript' at fault, per se. Actionscript its self is no worse than the other dozens of half-baked java-like scripting languages out there.

I blame the crappy Flash UI and the design for how they hooked the code up to their player. It's that whole 'WYSIWYG' thing they seem to have borrowed badly from Microsoft's Visual BASIC. There's always one more setting buried in one more dialog to make something work, and that model of 'scattering' your code to the nine winds in little 'hooks' doesn't help matters at all, nor does their lousy code editor and debugger, and the way you edit a 'class.as' file and it doesn't save it when you build. All minor little irritations.

That at least was my experience learning to use it.

As for your current problems, I'd abandon the UI controls and set up 'hot spots' on the stage that I managed myself. Cut out ALL the middle-men. Either point-in-rect with the mouse x,y or 'hitTest' on something on the stage with the mouse pointer when a 'mouse down' event happens.

If you still can't control-shift-delete and get your breakpoints to hit in the debugger, you have other issues.


BTW, would this be a nice point to rant about Version Control? I think it would. USE IT.
ummm...sorry, I have absolutley no idea what you are talking about...could someone please simplify?

pingnak
April 14th, 2007, 06:48 PM
Okie dokey. Leaving off the rant, here's some example code.
I made a shape (in this case a box, but any old MovieClip will do).
I dragged it to the library and exported it to Actionscript.
I Clicked on it on the stage, and brought up the Properties
I named it myBox
I put up a bit of instruction.
I put up a Dynamic Text called 'clickedMe' to tell me I'd done it.
I coded up a mouse event handler and hooked it up.
I used 'hitTest' to check if the mouse cursor was on the shape.
I change the text in 'clickedMe'.
Then I wrapped it in a state machine and made it reset its self.Pressing control-enter runs the code.

Pressing control-shift-enter brings up the debugger, at least in Flash Pro 8. If you have an earlier Flash, you might not have a debugger at all. Then you might want to try 'XRAY'.

You'll want more state to animate it, but I'm not writing your game for you.

hybrid101
April 15th, 2007, 11:05 PM
post your fla dude:)

ninja
April 16th, 2007, 02:22 AM
Okie dokey. Leaving off the rant, here's some example code.

I made a shape (in this case a box, but any old MovieClip will do).
I dragged it to the library and exported it to Actionscript.
I Clicked on it on the stage, and brought up the Properties
I named it myBox
I put up a bit of instruction.
I put up a Dynamic Text called 'clickedMe' to tell me I'd done it.
I coded up a mouse event handler and hooked it up.
I used 'hitTest' to check if the mouse cursor was on the shape.
I change the text in 'clickedMe'.
Then I wrapped it in a state machine and made it reset its self.Pressing control-enter runs the code.

Pressing control-shift-enter brings up the debugger, at least in Flash Pro 8. If you have an earlier Flash, you might not have a debugger at all. Then you might want to try 'XRAY'.

You'll want more state to animate it, but I'm not writing your game for you.


woah, great! Thanks for the fla! But...umm...one more thing...I have more then one beat in the song (obviously) So if I throw in that code for the 1st beat, it works great, the dynamic text goes from "0" to "1" when the movie clip is clicked. But is there a way to make it go from "1" to "2" (for the next beat) instead of going from "0" to "2"?

And also, if you missed one, would there be a way to go back to "0" and have the next successful hit go to "1"? .....I hope that paragraph made sense... :P

And as far as animation goes, I've already got all that covered.

pingnak
April 16th, 2007, 01:24 PM
Just add states to the state machine, or use more than one instance of state machine and have them invoke each other.

For instance, the state machine could be balled up in a class of its own, or copied and pasted into the script for each button with that button's unique behavior. Then you could cycle (or not) each script based on the button that needs to be pressed.

I don't have time today to be much more help than that.