Flash: comprensión del flujo del programa

After reading a tutorial of Flash, I am still not sure what exactly is the program flow in general:

Specifically, I have a demo of a flash game (sort of super mario style). In it I have two types of weapon - a simple fire and big fireball. I reviewed the code in order to learn flash better [I am very new - since around monday this week].

I saw that the program has a variable that keeps track of the number of uses I have left in each weapon. I tried to review all the places this variable was used but I couldn't find where it affects the drawing onto the screen.

I even tried removing the variable declaration and then testing it - so I may find all references to the variable -- By the way any convinient way of finding all references to a variable/method/class [I am using ADOBE FLASH CS5.5]? Also, I tried changing the variables starting value to "12" and I noticed that when I test the game, the weapon has 12 uses indeed.

So my problem: 1. It seems that this variable is somehow affecting the drawing. Yet, I don't know how it does so since all the code I have found that uses this variable has nothing to do with drawing. It is all, logic, like

if(var <= 0){
} else{
    return false;

Where is this influence coming from?

  1. Any way to get all references to a variable [like in eclipse ctrl+shift+g]?

Muchas gracias.

preguntado el 09 de marzo de 12 a las 14:03

1 Respuestas

Flash can have code on a variety of different things.

  • External classes
  • Movie clips
  • Cuadros

Depending on the tutorial they will put code on any and all of them and it makes it very hard to follow. In general it is always best to place code in external classes and only on frames when absolutely necessary. AS3, in fact, does not let you put code directly on movie clips to avoid just the problem you're having.

I'm going to assume you're using AS2 because of your problem of not finding code alongside of the fact you said you deleted the declaration of the variable and everything still worked. (AS2 lets you get away with a lot)

If you unlock any layers that are locked and select all, you might find almost invisible movies that appear as just dots. Lots of bad tutorials put code on invisible movies like that to run everything. Deselect everything, select just that movie clip and then hit [F9] to pull up the action window to see the code.

The other option is that the code is just on a movieclip somewhere. Start clicking on them and looking in the action window to see if there is anything there.

No matter what it sounds like you're using a bad example. Search for AS3 tutorials as that is a more optimized version of actionscript and it prevents a lot of bad practices like what you're seeing.

An AS3 tutorial I just came accross


To further answer your question, program flow happens with the flash VM first firing an onEnterFrame event which any movieclip can listen to. (In AS2 it would call onEnterFrame on every movieclip. This was abandoned in favor of the event so your class does not have to update on every frame) Once that has happened the VM then draws everything to screen. For a more complete overview I found this sitio web

Your problem sounds like everything is contained in external classes. Here's an ejemplo

respondido 09 mar '12, 15:03

When I deleted the declaration - things didn't work. However, all the errors I got where "logic" stuff and not any drawing command. By the way, it is AS3. - user967710

Ah! Ok now we're getting somewhere. There is no "draw" command in flash. Everything is done on the OnEnterFrame and everything takes effect immediately. There is no way to create other threads, there is just the draw loop. The only thing that can happen asynchronously is if you load images but the flash vm takes care of that for you. So basically if you change movieclip.x to be 20.. you've ACTUALLY moved the movie clip and it will be drawn as such. - AburridoAndroidDesarrollador

One thing you might want to check is to go into the library and get the properties on a movieclip. If it has a class then you need to look for a file ending in ".as". That will probably have the code you're looking for - AburridoAndroidDesarrollador

Ok. I understand your answer. Yet, I reviewd all the code and didn't find a reference to any "mouse click event" even though when I test the project, it has buttons to press. I also found these buttons in the library, like you said - looked at preferences and other options from the right mouse click menu, and yet noting. I even searched some of their names in the different as files, and also - no luck. So what I want to understand is where is it all hiding? - user967710

What demo are you working off of? If it's available online I can look and find all of that for you. It looks to me like this tutorial isn't stepping you through the code nicely though and for starting flash it's best to have some good tutorials. As for the mouse click event, you'll be searching for "[someMovieclip].addEventListener(MouseEvent.CLICK, <somefunction>);" That can be inside of any class or on the timeline (if a frame has an 'a' on it it means that it has actionscript code). - AburridoAndroidDesarrollador

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.