Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] ActionScript 3: communicating with parent object?

Started by Atrix256 Nov 18, 2009 at 1:49 PM 4 replies 2.4k views
Original Post
Atrix256
Atrix256
Hey Guys, I'm working on a game in action script and have it set up right now where... #1 - there is a main object that gets created that is going to be the base object of the entire game #2 - the first step is this main object creates a "titlescreen" object and adds it as a child to itself (both the main object and titlescreen object derive from sprite) #3 - my thought was that the title screen would load images (showing a loading bar etc) and as images loaded, it would tell the main object that an image was loaded so that the main object would keep the list of loaded images. #4 - i was also thinking that when images were finished loading, when the user clicks the "play" button, the titlescreen object would capture that event and let the main object know. the main object would then remove the titlescreen object as a child and continue on with the rest of the game. So... i was wondering... how can i get my titlescreen object to be able to call a function of my main object? Also i was wondering, is this a decent way to go about doing things or is there some better ways that i'm overlooking? Thank you!
Wan
Wan
Quote:
#2 - the first step is this main object creates a "titlescreen" object and adds it as a child to itself (both the main object and titlescreen object derive from sprite)
Quote:
#4 - i was also thinking that when images were finished loading, when the user clicks the "play" button, the titlescreen object would capture that event and let the main object know. the main object would then remove the titlescreen object as a child and continue on with the rest of the game.

Sounds like a job for a FSM. Whether it's better that the game object is a FSM, contains a FSM or implements a FSM interface would be up to you.

Quote:
#3 - my thought was that the title screen would load images (showing a loading bar etc) and as images loaded, it would tell the main object that an image was loaded so that the main object would keep the list of loaded images.

Does this all need to be a part of the central main object? All the loading screen needs is a (reference to) a list or pool of images.

Quote:
So... i was wondering... how can i get my titlescreen object to be able to call a function of my main object?

You can always pass the parent object to it's constructor:
public class Child{  public function Child(parent:Parent)  {  }}
Atrix256
Atrix256
Thanks Wan (:

Yeah, this is turning out FSM like where each screen has it's own class. It's working nicely though, thanks for the tip.

I'm hitting another problem though, would you happen to know if a bitmapasset is incapable of getting a click event callback attached to it?

I have some members like this:

    [Embed(source="SoundOn.png")]    private var ImageSoundOnEmbeded:Class;    private var ImageSoundOn:BitmapAsset;


then in the constructor i do this:

      ImageSoundOn = new ImageSoundOnEmbeded();      ImageSoundOn.x = 0;      ImageSoundOn.y = 343;      ImageSoundOn.addEventListener(MouseEvent.CLICK,ClickSoundButton);      addChild(ImageSoundOn);


I see the image SoundOn.png on the screen just fine, but when i click it, the "ClickSoundButton" is never called. Verified with putting a trace inside ClickSoundButton (and other code).

This works with shapes in other places as well as TextFields so is it just that it doesn't work with BitmapAssets?

Thanks!
Wan
Wan
A bitmap is basically just a collection of pixels. To receive and register mouse input you'd need to make it a least a sprite, but in this case a Button (or SimpleButton) is probably the most appropriate solution.

Check the Adobe documentation for more information.
fnm
fnm
Quote:
Original post by Atrix256
I'm hitting another problem though, would you happen to know if a bitmapasset is incapable of getting a click event callback attached to it?


Have you tried setting its butonMode property to true?
Atrix256
Atrix256
Thanks guys,

I put it inside of a sprite and it worked well.

i'll check out the button and simple button types and the buttonmode property as well.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.