Search Results

Search found 2 results on 1 pages for 'madcowe'.

Page 1/1 | 1 

  • Create and use a Button class on AS3.0

    - by Madcowe
    I am currently working on a game and it is all going well. On the shop screen there are several buttons that affect the player's stats for when the player restarts the game. The button's names (with a text on the left), however, are rather cryptic and it's hard to figure out what they do unless you test or something. So the solution I came up with, is to create an InfoBox with an InfoText inside so that when the cursor is over the button it appears with the description, cost and etc. This I managed to do too however, the way I was about to do it would mean that I had to create 3 event listeners per button (CLICK, ROLL_OVER, ROLL_OUT) and, obviously, 3 functions connected to each event listener. Now, I don't mind much about having 1 event listener per button, for the click, but since the other events are just to make a box appear and disappear as well as display some text, I thought it was way too much of a mess of code. What I tried to do: I created a new class called InfoBoxButton, and this is the class' code: package { import flash.display.SimpleButton; import flash.display.MovieClip; import flash.ui.Mouse; import flash.events.MouseEvent; public class InfoBoxButton extends SimpleButton { public var description:String; public var infoBox:InfoBox; public function InfoBoxButton(description) { this.addEventListener( MouseEvent.ROLL_OVER, displayInfoText, false, 0, true); this.addEventListener( MouseEvent.ROLL_OUT, hideInfoText, false, 0, true); } private function displayInfoText() { infoBox.infoText.text = description; infoBox.visible = true; } private function hideInfoText() { infoBox.infoText.text = ""; infoBox.visible = false; } } } But now I don't have an idea how to associate it with the button, I have tried this: public var SoonButton:InfoBoxButton = new InfoBoxButton("This is merely a test"); The SoonButton is a button I made on the shopscreen, SoonButton is it's instance name, but I can't think of a way of associating one button to the other... I have been fiddling with the code for like 3 hours yesterday and no luck... can anyone give me some pointers on how I should go about doing it?

    Read the article

  • Affect movieclip scale from a .as doc to another

    - by Madcowe
    I've been working on a game following a tutorial on the internet, the game is an avoider where you have the Avatar, that has to avoid the objects that fall. The way it is made is: I have a DocumentClass which addChild's the screen you should be seeing and removeChild's the screen that you were. For example: first it loads the menuScreen, then when you press play unloads menu and loads playscreen. When you die it loads the gameoverScreen and loads the playscreen. And from the gameOverScreen you can press the SHOP button to go to the shop. From here on I'm on my own and not following any tutorials. The shop has a button that is supposed to alter the Avatar's X and Y scale to 0.5, but the problem is: how do I make that work? I tried creating a sharedObject.data.avatarSize, on the store's size button the code would be something like: sharedObject.data.avatarSize *= 0.5; And on the AvoiderGame.as, which is the most of the actual game, on the part where the avatar is created I tried putting this after it's creation: scaleX.avatar = sharedObject.data.avatarSize; scaleY.avatar = sharedObject.data.avatarSize; This did not work since it gives me the error 1009 saying can't access something that is null. I tried this before "using" the sharedObject: if( sharedObject.data.avatarSize == null ) { sharedObject.data.avatarSize = 1; } But it did not work... So now I'm not sure on what to do. I know we should reduce global variables as much as we can but how do I do it? Also, if it helps, I'm using Flash CS5 and working with AS3.0

    Read the article

1