PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[AS3] Making an 'Escape the Room' in AS3
A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: [AS3] Making an 'Escape the Room' in AS3

  1. #1
    Member
    Join Date
    May 2005
    Posts
    95

    [AS3] Making an 'Escape the Room' in AS3

    Hello,

    So I am continuing my long switch from AS2 to AS3 finally... and I thought I'd start by making something simple. An "Escape The Room" type game, should be easy right? Just pointing and clicking?

    Wrong.

    Man, I am horrified how much I am dependent on coding on objects!

    So many questions...

    I loaded up my file for folks to look at.. I guess my big question is what I did wrong.. I thought i set up the buttons correctly and my Event Listeners.

    nail_mc.addEventListener(MouseEvent.MOUSE_DOWN, objectFound);

    But Flash doesn't like SOMETHING I did :P


    Any insight into this would be much appreciated

    Here is a link...
    http://www.filefactory.com/file/b2bf...E_THE_ROOM.fla

    I should be able to click and drag things if I knew what I was doing :P

  2. #2
    Senior Member
    Join Date
    May 2010
    Location
    Russia: Western Siberia
    Posts
    268
    If you wanna drag the object you clicked, you have to use its startDrag() method.

    Actionscript Code:
    nail_mc.addEventListener(MouseEvent.MOUSE_DOWN, objectFound);

    function objectFound(e:MouseEvent):void
    {
         nail_mc.startDrag();
    }


    btw. I can't open your file in flash cs4. You probably saved it in cs5. I think you'd better save your files in older formats if you want other people to be able to open them

  3. #3
    Member
    Join Date
    May 2005
    Posts
    95
    Sorry about that... I am making the jump from Flash MX to CS5 and I have been using MX so long I am used to being behind everyone else :P

    Anyway, yeah it was saved in CS5, so here is the new file

    http://www.filefactory.com/file/b2bf...HE_ROOMCS4.fla

    I didnt just want to copy and paste your code in there all crazylike lest I break something even worse.

  4. #4
    Senior Member
    Join Date
    May 2010
    Location
    Russia: Western Siberia
    Posts
    268
    Well, seems like the code tries to access some object that has not yet been created, on frame 1.

    I'm not sure how did as2 work (since I don't know it at all) but in as3 it's impossible. All of the objects you want to access from the first frame must be created first.
    I suppose you tried to add some event listener in the first frame to an object that appears in the second or third frame only

  5. #5
    Member
    Join Date
    May 2005
    Posts
    95
    Aaaah I seee.. so let me try and finish the whole thing first and then repost it.

    In AS2 youd write a function or whatever and then it would access the art at the same time.

    So youd write some code telling the button to work.... and then put some code in the button that the code would access.

    I can see how AS3 would be more efficient, but it is taking some getting used too... So, I would only put the event listeners on teh pages where the object is initially found? What happens if they pick up a hammer and drag it on another frame?

    Okay I want players to move the drum of toxic waste, pick up the hammer, than go to the appropriate wall ( I think its east ) then use the hammer to pull out the mail and pick the nail up.

    Would the event listener be on teh frame you initially find the hammer? and then use it through out the rest of the game? I am not sure if AS3 has globals... I dont think it does.

    Anyway any insight would be great

  6. #6
    Senior Member
    Join Date
    May 2010
    Location
    Russia: Western Siberia
    Posts
    268
    Event listener doesn't necessarily need to be on the same frame with the object you add it to, but it has to be added to the object that already exists. For example you have a hammer created on the 2nd frame and it keeps on living on the 3rd and 4th, so you can add listener to the hammer on the 2, 3 or 4th frames, because flash will already know about the hammer's existence.
    I hope it's not too confusing

    p.s. To get it started with as3, I'd recommend you to read Colin Moock's Essential ActionScript 3. Absolutely awesome book, it was actually the first book I read on as3 and I liked it a lot

  7. #7
    Member
    Join Date
    May 2005
    Posts
    95
    Uh, it is VERY confusing.

    So if I add

    nail_mc.addEventListener(MouseEvent.MOUSE_DOWN, objectFound);

    to the 2nd as frame, it should work correct? Since once the player goes to frame 2, the hammer will load and Flash will know what it is in sequential frames?

    I actually looked at "Essential ActionScript 3" but amazon.com reviews mention its probably not the best for newbs... so I passed.

  8. #8
    Senior Member
    Join Date
    May 2010
    Location
    Russia: Western Siberia
    Posts
    268
    If the nail_mc exists on the second frame, it will work correctly.

    I actually looked at "Essential ActionScript 3" but amazon.com reviews mention its probably not the best for newbs... so I passed.
    I can surely say, it's one of the best books for newbs

  9. #9
    Member
    Join Date
    May 2005
    Posts
    95
    Nope, still nothing

    Grr if I can get this working I promise I will get a copy of that book....

    Well, I'll probably get it either way, but I'd still like to get the basis of this working today :P

    http://www.filefactory.com/file/b2bg...HE_ROOMCS4.fla

    I can't thank you enough for being so patient with me :P

  10. #10
    Senior Member
    Join Date
    May 2010
    Location
    Russia: Western Siberia
    Posts
    268
    I think it would be better to create all of those objects on the 1st frame, and then change it's visibility property. Like this:

    Actionscript Code:
    nail_mc.visible = false;
    Once you pass to the second frame, you can make it visible again
    Actionscript Code:
    nail_mc.visible = true;

    This way you can make sure you have all of the objects created when you need them

  11. #11
    Member
    Join Date
    May 2005
    Posts
    95
    Hmm okay, sounds logical since that is very similar to what I wanted to do with the inventory 'version' of the objects

    But i am still getting that

    "Access of undefined property objectFound" error. and I have no clue how to fix it. since even now when all the objects and code is on the first frame, I still get that error. There has to be something I am missing.

  12. #12
    Senior Member
    Join Date
    May 2010
    Location
    Russia: Western Siberia
    Posts
    268
    Have you created objectFound() function? I couldn't find it in your file

  13. #13
    Member
    Join Date
    May 2005
    Posts
    95
    Oops.

    yes, that would help. Duh.

  14. #14
    Member
    Join Date
    May 2005
    Posts
    95
    Okay I got a little further on it.

    But on teh frame I want the drum to appear I added the code

    drum_mc.visible = true;


    That should make it appear when the player clicks on that room correct?

    Instead, now I get this error:


    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at ESCAPETHEROOM_fla::MainTimeline/frame3()
    at flash.display::MovieClip/gotoAndPlay()
    at ESCAPETHEROOM_fla::MainTimeline/eastTOsouth()


    So obviously I screwed something up.... but what?

    And once again, here is the .fla

    http://www.filefactory.com/file/b2bh...HE_ROOMCS4.fla

    AS3 is rough :P
    Last edited by Axiomonline; 07-27-2010 at 08:04 PM.

  15. #15
    Senior Member
    Join Date
    May 2010
    Location
    Russia: Western Siberia
    Posts
    268
    So obviously I screwed something up.... but what?
    The problem is caused by drum_mc. If you comment that line out you won't encounter this problem. And the reason for this is that you don't have drum_mc on the third frame at all. You have hammer, key, invote, invail in every frame, but the drum is present only on the first one. Obviously it should also be on every frame


    AS3 is rough :P
    I wouldn't say so. It's a good language, but probably takes time to get used to after as2

  16. #16
    Member
    Join Date
    May 2005
    Posts
    95
    caseyryan man I can't thank you enough! I wonder if I can mail beverages to Siberia :P

    Yeah those mistakes last night were pretty dumb... but it was getting late.. I should've packed it in hours ago :P


    ok. I can move the drum. But when I click on the objects they arent 'going into the inventory'

    Another thing Id like to pester you about is how to click on something and play an animation in AS3. Id like the player to find the hammer. pick it up. click on teh nail in the wall to pull it out *animation of nail falling to the ground* then the nail can be added to inventory.

    I wrote out my pseudo code but again I am not sure of the syntax AS3 uses.

    ***Btw I ordered that book from Amazon last night. Should be here in a week***

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