PDA

View Full Version : [AS3] New to flash actionscript, making a game.


pimpofpixels
06-12-2007, 11:36 AM
Hi. My name's Rory.

I am an artist.
http://www.youtube.com/profile?user=PimpOfPixels
http://roaring23.cgsociety.org/gallery/

I am learning action script and Flash so that I can make games.
I am not a complete novice in programming. I am proficient in Java and in MaxScript (3DSMAX embedded language).

I have been making some progress in action script and I have a functional (although incomplete) game in the works. You can view it here:
http://secure2.streamhoster.com/~rlutter/roaring23/colorniverous.swf
The idea is it's a color game
red beats green, green beats, blue beats red. Think paper scissor rock.
The idea is to change the entire circle into one color.
The graphics are place holders BTW.

I am using FlexBuilder 2.0 and Flash CS3, and I have come across a problem not covered in either of my books.

I'd really appreciate any help that you guys can offer.

I have gotten this far on my own.

My #1 question (and I have many more) is:

How do you through Flash specify animation segments for a MovieClip Symbol?

Notice how the red creatures occasionally open their mouths. I want to have a walk, an attack, an absorb, and a bounce animation on the same timeline and trigger the appropriate one depending on which color the creature collides with. I do not know how to go about this problem. I’ve just been trying to get the walk animation to loop without playing the attack animation so far.

I've tried frame-labeling in flash, with scripts on the key frames of a second layer that specify when to stop or repeat the animation... No dice.

I am really starting to run out of different ways to bang my head against this problem. Please help me :)

-Rory-

pimpofpixels
06-13-2007, 01:29 AM
Thanks to the 18 people who looked. I'm hesitent to let this thread die since I'm not sure where else I can turn to solve this problem.


My question
How do you subdevide segments of animation along a symbol's timeline into separate animations?

Thanks for any help you can give me.

I promise that I'll stick around as an active member of this forum and I will answer rookie questions like this once I've got the know-how.

Thanks

http://secure2.streamhoster.com/~rlutter/roaring23/colorniverous.swf

evride
06-13-2007, 03:01 AM
first of all i like your design skills. Im not much of a designer. not even close to you so i have to compensate by having good coding skills though i am quite unfamiliar with AS3. I only have the Flash CS3 public alpha and it seems everything i do i get 20 errors. AS2 didnt seem to transfer over to well. :confused: :rolleyes:

i think i know what you want.

go into your movieclip that you want to create different movements for.
put all movements in that one movieclip.
on the first keyframe of each action label it something memorable like "walk" or "eat".
Do this by clicking on the desired key frame and then bring up the properties box and put the name in the text box labeled frame.
in the last key frame of the action add this code
gotoAndPlay("walk");
//instead of "walk" put the frame label that it needs to loop to.

move the movieclip to the main stage and give it a an instance name of mc_name

then create functions on the main timeline (that means not on the movieclip. deselect all movieclips)

function walk(){
mc_name.gotoAndPlay("walk");
}
function eat(){
mc_name.gotoAndPlay("eat");
}

then you just have to initiate the function.
you action. you can do this several ways.
one way is just typing in the function name like so

walk();

or you can do it on key press or mouse press like so
mc_name.onPress = eat();

you can do for pretty much any event.

i hope this helped.

evride
06-13-2007, 03:10 AM
i'm making a game. It's quite large. uses an xml socket server. and a lot of actionscript. might need help with some graphics. do u charge a lot?

pimpofpixels
06-13-2007, 04:16 AM
I am working on this, but to answer your question.

I am in a sabbatical. I am trying to switch careers from 3D wireless tech to video games.

At this point I don't do a lot of work for money. My only goal for the next 8 months is to get ready for a game job. Learning how to create "fun" is my current mission.

I'll happily trade programming tips for graphics.

pimpofpixels
06-13-2007, 04:27 AM
Thanks for your thorough and articulate reply. I really appreciate it.

The symbols that I am embedding into my FlexBuilder project are still looping right past the gotoAndPlay events.

It is curious because upon exporting from flash the window it opens of the exported swf file has the symbol looping properly.

I wonder if my problem is that the Symbol is being cast as a movie clip inside my project?

evride
06-13-2007, 05:09 AM
i'm sorry i dont know anything about Flex, just AS and flash. I don't understand why you need Flex for what you are trying to do. Most games can be made in Flash easily without much help.

pimpofpixels
06-13-2007, 05:09 AM
I have a symbol named RedShot in the library of a flash project named "graphics"

In my timeline I have 2 animation segments, and I have a second layer denoting two corresponding frames named "walk" and "attack" from the properties menu.

On the final frames of the animations I have scripts.
gotoAndPlay("walk"); and gotoAndPlay("attack"); respectively.

Im my library I have linkage options specified as such:
Class:RedShot
BaseClass:flash.display.MovieClip
export of actionscript#CHECKED
export on 1st frame#CHECKED

on the main stage of my flash project I have actionscript for 2 functions:


function walk(){
red_shot.gotoAndPlay("walk");
}
function attack(){
red_shot.gotoAndPlay("attack");
}


I export the project and the opened window has the "walk" animation looping properly.

In my FlexBuilder project I embed the symbol

//Inside class global variables:
[Embed(source="../graphics.swf", symbol="RedShot")]
public var RedShot:Class;
private var _shot:MovieClip;

//and in my buildShot function:
_shot = new RedShot();
addChild(_shot);


When I build the project the characters appear, and they animate. The only trouble is that there are no breaks in the animation. The animation loops right through the frames where I have specified that the animation should "gotoAndPlay" from a different part.

What's weirder is that I can call "gotoAndPlay("attack");" without an error and it will go to and play from that point. The only trouble is that it will begin to loop the entire animation again without stopping at the gotoAndPlay events stored in the frames of the timeline.

Any thoughts?

sasxa
06-13-2007, 05:32 AM
looks to me the solution to your problem is as simple as adding stop() at the end of each animation segment on timeline... If you have one animatin segment from frame 1 to 50, just add empty keyframe at 50, and add stop() action. than create another segment, from 51-100, add stop() at frame 100 etc...
am I missing something or is this what you need?

pimpofpixels
06-13-2007, 05:41 AM
The problem seems to be, no matter what actions I embed in the symbol they get completely ignored after they're embedded.

pimpofpixels
06-13-2007, 06:26 AM
Perhaps flexbuilder was a mistake.

The book I got "assumed" that I had it so quit what I was doing in flash (and I was making a lot of progress) and started learning to develope in flex builder.

Now, I'm beginning to think that what I'm trying to do just isn't supported.

evride
06-13-2007, 11:26 AM
hmmm...
interesting problem you have here.
try this.
move those actions of walking etc into their own little movie clips. add no code to it.
then in the character movie clip create one frame for each action that the character is going to do. label those frames
then nest the action movie clips into the character movie clip
make sure no actionscript is on the character movie clip.
now for your functions on the main timeline change the gotoAndPlay to gotoAndStop

evride
06-13-2007, 11:38 AM
I'm sorry but i still don't understand why you have to use Flex? Flash is capable of doing what you want by itself. jumping between programs to design makes it a bit more cumbersome i believe.

pimpofpixels
06-13-2007, 01:02 PM
Thanks EVDog for your help. I REALLY REALLY appreciate it. You must be a very good person. :)



After hours of searching the internet I finally got this blasted question figured out.

How to you export a symbol from Flash for use in a Flex Builder project without destroying actionscript stored within the frames of the Symbol's timeline?

That's a long winded way of saying: "In FlexBuilder, how do you control MovieClips from Flash". I'm trying to make games, and this was a particularly important question for me :).

Here's how:

1) You need a hotfix from Adobe.
http://kb.adobe.com/selfservice/viewContent.do?externalId=kb401493&sliceId=2

This allows Flash CS3 to export a SWC file.

2)You have to set the linkage properties for your various symbols in the flash library panel.
a)right click on symbol in library panel
b)choose "linkage"
c)"Class:" = (pick a name)
d)"Base class:" = flash.display.MovieClip;
e)"Export for ActionScript" = CHECKED
f)"Export in first frame"=CEHCKED

3)If you want to have multiple segmented animations as I certainly did you'll want to create frames and actionscripts within the symbols timeline to define where these animations are.
a) in the symbol's timeline make a second layer. We'll name that layer "labels" for the sake of not having this get too confusing.
b) on that layer create a new frame for each of the animation segments that you'd like to define and stretch them to the length of the corresponding animations.(I'm assuming that you have a keyframe animation on the 1st layer... otherwise what's the point of all this :P?)
c)in the properties panel name the frames in the "labels" layer accordingly ie. "walk" "run" shoot" etc.
d)Define whether the various animations play once or loop by adding a script to the last frame of the animation. If you want the animation to loop add
gotoAndPlay("name-of-the-animation");
if you want the animation to play once and stop add
stop();
if you want the animation to play once and then return to a different animation add
gotoAndPlay("name-of-a-different-animation");

4) now you can export the symbols to an SWC file. Note: you do not get this option unless you have installed the hotfix. http://kb.adobe.com/selfservice/viewContent.do?externalId=kb401493&sliceId=2.
a)rightclick on a symbol in the library panel
b)choose "exportSWCfile..."
c)export the file to a logical place such as the root of your FlexBuilder project.

5) Now you have to tell flexbuilder about the new SWC file. Note: Once this file is added to the FlexBuilder library you can instantiate classes from it as though they were included using the "include" function.
a)Right clicking on the root of the project in the Navigator view.
b)go in to properties.
c)Go in to library path. (2nd tab)
d)and press the "Add SWC" button

Now you're done and you can instantiate any of the symbols from your library while preserving any actions from your symbols timeline just as though you had imported it as a class from a typical library.

Sweet huh?

Thanks to the countless people and internet resources I found on the subject. Hopefully it will be easier for anyone who finds this post than it was for me.

Here's an adobe video which covers the basic process.
https://admin.adobe.acrobat.com/_a300965365/p75214263/