Saturday, September 26, 2009

Case 03 - Final

This is the last post about the third case. As mentioned earlier the scope was to use ActionScript to program the sprite, making it move back and forth in the picture "bouncing" off the edges.

It wasn't really before thursday that I figured out how to do it, all my other trys the days before failed as said. But when we were going through the case with the teacher and a lab assistant they got the same problem I had struggled with the last three days. This was a good thing, at least for me, 'cause then the teacher and assistant had to figure out what was wrong, and by doing that, they showed how to sovle the problem I'd been having.

So when I finally had succeeded in writing a code that made a box bounce off the walls, I changed the code so that my character would replace the box. This was pretty nice because for the first time that week I felt that I managed to get something right.  ^___^
Steffen aslo showed my how to flip the character so it wouldn't run backwards. That's pretty easy, you basically just add the if command and tell the character to .scaleX = -1 one way, and .scaleX = +1 the other way.

Anyway, now I'll tell you more specifically what I did to make this work and complete the third case.
  • First of all I created a new folder and called it "Case 03". This folder was my container for the animation (.fla file) and the script file (.as file).
  • Then I copied my flash file with the animations and my sprite into the folder.
  • Next thing to was was to open Flash and create an ActionScript File. That was the file in wich I wrote the code. Then I savd it as "Document.as" in the Case 03 folder. For this to work the .as file and the .fla file must be in the same folder, otherwise the script can't access the objects in the flash library and make the magic happen.
  • Next up was to ensure that the script file could associate with the .fla file, to do this I went to the properties of my flash document and named the Class of the file to Document - but without the .as at the end. As far as I've understood this has to be done if not the files won't communicate correctly and you'll encounter problems when the script is trying to use ojects from the library.
  • The last thing that had to be done before starting to write the code was to make sure the oject you plan on using can be accessed by the actionscript. To do this I went to the properties page of my walk animation (wich I had decided to use for the experiment) and made sure that:
  • The type of the objetct was Movie Clip.
  • It was ready to get exported for ActionScript.
  • Aslo export in frame 1.
  • Check that the the Class was Walk (the name of the animation).
  • Check that the base class is flash.display.MovieClip.
  • And finally choose the source almost on the bottom of the properties page. To do this I pressed "Browse", and found the .fla file I was working with. When I chose it a new window popped up with the objects in the library, I simply then marked Walk and clicked "Ok".
    • Now all the preparations was done and I could start to write the code.
    • What I did was to follow what the teacher told during the lab while the assistant showed what he wrote on a projector. I tried to write stuff by myself also, to see if I could remember anything from the books I read. Wasn't much though. It's still pretty overwhelming stuff for me :)
    • After writing the code, I added a shadow and made it follow the character while it moved from side to side. But took it away, and made the character turn around each time it reached a border instead, thanks to Steffen ;)
    You're probably getting bored of reading my post now, so I'll add a preview of the flash file with the character running back and forth.



    Case 03 by ~Elr0hiR on deviantART

    1 comment:

    1. Nice and organized post, I had no idea how to finish the blog about this case, didn't know what to "add" of information, so I had to use your blog as a reference to finish mine :P

      And btw. Thanks for mentioning me! =)

      ReplyDelete