00:00
00:00
Minix07
what is goodie in da hoodie gangalang?

ima dude, dude

Human

Highland High School

was british land

Joined on 1/13/24

Level:
8
Exp Points:
656 / 710
Exp Rank:
> 100,000
Vote Power:
5.04 votes
Rank:
Police Sergeant
Global Rank:
8,100
Blams:
211
Saves:
947
B/P Bonus:
12%
Whistle:
Normal
Medals:
254
Supporter:
15d

Making a click n' point game using AS3 | Steps 2 & 3

Posted by Minix07 - 3 hours ago


This is a work in progress tutorial. It's unfinished, and as such, you should ignore it until it's done.



Step 2. Make a da button work

AD_4nXeqneuIwrQ8l0LSp6XCZmfKUtlSsmtT0Vpu0vsg6QaBFPp9dxhCzeOVFYjJgjTtH_eiTo2pTAk0dScQ3BEIAG2TUIM3XoZQDUjW0qZYD2opCUPWXtq41HYjDHAzGIFpIrzC3jd2uA?key=lYln-58pvChvGvHg5Z5QrA


Here is how it should be nested, root being the start

Do whatever you want on the main menu, I won’t tell you what to put. Now, create a start button.


AD_4nXfN4KOYXPYbImz6i9swaZX0LGjUL36fBG2pf8MZOEvelUGHKtm0ftEIXfsVxriTLFyeZQce49ccPS-4W4HjG_xj9PHgZpcPuU-ZAbfddnM60eRJqHjtFQ692Q_yv3V7Rrue0L-TvA?key=lYln-58pvChvGvHg5Z5QrA


It’s pretty ugly, I'm sure you can do better.


AD_4nXeV-BLuj-I7ne-FKyCKPmh_5AWReX3cBd2EHPztmLYmQ1J9dtqTgzQGZBr39fh6-t4f8GjH-zmE81wXRMMOax3NNKYoASh0-VeCBeM_4YlbJejjJQH9t5XRxUvR-s1HZYCo0ZVNiA?key=lYln-58pvChvGvHg5Z5QrA


Convert it into a button and create the necessary frames for it.


AD_4nXehBbeOwFTH069wSu6d2dK4DRq-sPBRnyXnpMScDEeY6NoRlnajvl-IV4TPgu_RLZmHEHhPXzdwBvMrRRKX1NLmdVw6L95MACuInFx_OeI5B8siCShr_wIM4H4S6pQM6_T_RLNQbw?key=lYln-58pvChvGvHg5Z5QrA

Here is what each of the frames means for a button.

Up - The Button goes here when idle

Over - The Button goes here when the mouse is touching it

Down - The Button goes here when the mouse is pressing down on it

Hit - Hitbox of the button. If not defined, it will use the Up frame as its hitbox. This frame is never shown


Once it’s done being made, exit the symbol and give it an instance name using the property panel.

AD_4nXdcnyxXLfA0lZXSAWOqESazz9TINgrkvoj98vDVJhOExNkp0RYOIypvrCQzpY0UcA1Ta7pqKtbQFnru8KE6rbmbnFMgQOwxfXJHT5yWjoJyFL71Kya4LclDB3-j2M9qivVJbmhO4w?key=lYln-58pvChvGvHg5Z5QrA

An instance is the name given to MovieClips and Buttons to access them via code. There are some rules about what names you can pick

  • Has to start with a letter
  • Can contain numbers, underscores, and dollar signs anywhere else
  • Can’t contain keywords (words that do certain things)
  • Can’t contain spaces
  • Can’t contain swears
  • I made the last one up :P

It’s also common practice to end your instance name with “mc” if it’s a MovieClip, “btn” if it’s a button, and “tx” if it’s text. This is to avoid a potential conflict with keywords or something like that; you can absolutely not do that if you want.

If you are still with me, in the main menu, create a new layer and call it “actions” or “code” or anything that reminds you that's where the code goes. 

Put it where it can easily be found (like the top or bottom). 

AD_4nXeto-kO1fSiiQxhqCruZGKbiMgAgxExTg30slyYwuC_cCbTP9UM_G38dfUEUcMATHs0N2FS9IcbP-9IVvVYse_KtKAz_qz1iIxN3JNmeQ65g_-7jmfCY_rYHhW6o7LUaUs05YNH?key=lYln-58pvChvGvHg5Z5QrA

Select the frame and open the Actions panel (F9). To make the button interactable, we need to give it a task. Thankfully, AS3 has a way to sort “Assign orders” to movieclips using “addEventListeners”.

Start by writing the start button instance name and include the "this" keyword at the start to make sure that Flash knows it's referring to the start button from this EXACT location.

this.startbtn


Now, add an event listener to it like this and add parentheses next to the addEventListener, with a semi colon at the end to tell flash that's the end of this line and to move on (it's optional btw)

this.startbtn.addEventListener();


Now we have to specify to startbtn that it needs to look for a click from the mouse, this can be done like this

this.startbtn.addEventListener(MouseEvent.CLICK);


So we’ve assigned the startbtn a task, that is to report when it has been clicked by the mouse. However, it has nothing to do with this when it is activated. To make it work, we need to add a function.

this.startbtn.addEventListener(MouseEvent.CLICK, startgame);


This gives the startbtn the task to listen for when it’s been clicked by the mouse, when it does get clicked, do the startgame function, which right now doesn’t exist soooooo…

Start by typing in the function and then the name

this.startbtn.addEventListener(MouseEvent.CLICK, startgame);

function startgame


Then put parentheses and inside of them type “event:MouseEvent”. Also, add “:void” at the end to signify that nothing is being returned to the function, again common practice that doesn’t necessarily need to be followed.

this.startbtn.addEventListener(MouseEvent.CLICK, startgame);

function startgame(event:MouseEvent):void


And add brackets (or whatever you call them) like this

this.startbtn.addEventListener(MouseEvent.CLICK, startgame);

function startgame(event:MouseEvent):void {

}


Or you can do them like this (which takes up more lines and therefore is the inferior way of doing it)

this.startbtn.addEventListener(MouseEvent.CLICK, startgame);

function startgame(event:MouseEvent):void 
{

}


So let's take a couple of steps back and see what is going on rn. startbtn is given an EventListener, a task to call the startgame function anytime startbtn is clicked. Currently, the startgame function does nothing when it should be starting the game, which doesn’t exist…


Step 3. Make Cutscene

This is optional; if you don’t want to see a cutscene after playing the game, go to step 4.

From the root of the timeline, enter the game symbol and make an empty frame; the cutscene will be on here. 

AD_4nXdOPrIRXMcx2Km1K-pecea9rxbTGeOOkywMPk1VjNlifV2oD2YgpMTzvyEfSGwasgiyB3JxYPk1aPH_s1pZm5qhT6jsfqVnKG-8-BzON8mzJVLrrKvMSjr_CeNwzMN41v54QsS3kg?key=lYln-58pvChvGvHg5Z5QrA

Make the background and convert the symbols. 

AD_4nXeIhwVak8Ym3nIc4g5GGrbRiooaZJwXausa0HM4rN6bhFa6IU192E1_WLTDtux2PH6nopcWjM4gt098ejSpGezFzgBbrpqXW6h8RDMlFE5fj3sr1cowicAdjeCsXJiVGT5Pc6sU7A?key=lYln-58pvChvGvHg5Z5QrA

Inside this symbol, animate your cutscene. Use as many layers as you want.


Tags:

1

Comments

Comments ain't a thing here.