Skip to main content
Participant
March 19, 2011
Question

Making things happen in the right order

  • March 19, 2011
  • 1 reply
  • 499 views

As an experienced programmer, but an Actionscript novice, I am having difficulty persuading AS3 to deliver this:

I want to put a series of identical things on the screen, in different but predictable places.  It seems ideal to use a "for " loop, incrementing the x and/or y coordinates each time.  However this puts the items on the screen too fast - I want them to be seen arriving, so I am trying to have them arrive at specific intervals.  "Timer" fails to work because I can't use it to increment the counter (as would be easy in a "for" loop).  Then I want to add more items but have them wander about the screen - by incrementing their x and y with random numbers - sounds easy, but I can't find a way to initialise the location of each item before using .x+ and/or .y+.  Again I want to slow this process down so the user can see what is happening - needing some sort of timer.  Finally (for the moment) I can't seem to stop AS3 doing lots of things in parallel, whereas I want them to happen in a specific sequence.  How do I force things to happen in a specific order?

Don't suggest that I use frames and tweens because I don't want a movie animation, I want a controlled simulation, which will look different every time and will respond to different user input.

Thanks for any advice - I'm pretty depressed about AS3 at the moment.  FORTRAN 77 would work a whole lot better, if it had access to Flash graphics!

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
March 19, 2011

actionscript is an object oriented programming language.  it works different from a sequential language like fortran.

you can use the timer class or an enterframe loop or setInterval() to do what you want.   in as3, the timer class is the most flexible.

there's no problem incrementing a counter in your listener function.  in addition, the timer class has a currentCount property that increments for you when the listener function is called.

Participant
March 20, 2011

Thanks, kglad.  You mention a couple of functions I had  not come across (setInterval and currentCount) despite reading about  Timer.  I will have a look at them.

One major problem I have trying to learn AS3 is that there does not seem  to be a decent reference work.  I can't find a comprehensive list of  functions (classes or whatever they are called in AS) with their  possible list of parameters and so on.  I am therefore forever not  knowing what to look up, because I don't know what it is called in AS3.   The ActionScript Manual has no such list and although I can search it, I  don't know what terms to use.  e.g. I can search for "wait" or "delay"  or "order" or "sequence" (which all seem to me to be reasonable things  to look up, but none of which appears in the index) and all I get is a  load of useless hits in the text. 

There is a thus a catch 22:  until I know that something exists and what  it is called, I can't look it up and find out how to use it!

You say (and I'm sure that you are right) that I can achieve everything I  want to using Timer and its associated classes.  If so, can you direct  me to any examples of code which might lillustrate this? (Because I have  spent many hours on this already without success).

My other comment on my experience with AS so far is that it is very  verbose - perhaps this is endemic with object-oriented languages, but I  find that it takes 2 or 3 times as many lines of code to achieve an  effect than in any other language I have used.

I'm still keen to learn, but at this rate my first simulation will take more than a year!

kglad
Community Expert
Community Expert
March 20, 2011

the key document you need is a list of actionscript classes.  in the help files:

actionscript 3.0 language reference and components/all classes.  every class is listed.  within each class, its methods, properties and events are listed.

(there are also functions like setTimeout(), setInterval() and navigateToURL() that are not listed under classes but these are most quickly found by asking here or using google to find what you want:  flash as3 link to url, for example.

anyway, the main document is that class list.  now, unless you read the programming actionscript 3.0 section of the help documents or you have some experience with oop languages, you'll have no idea what class you need to check to find what you want.  i don't know any way around that issue.  either read about how to use as3 in the help docs or elsewhere so you grasp the most used classes or you'll need to use some reasoning and luck to find the class that has what you need.

for example, in this issue, you might have scanned that list and found the timer class because that looks like it has something to do with timing of events.  of course, if you were looking for how to determine the time of day, you might check that class too and fail to check the correct class, the date class.  but that's where luck comes in until you have experience.

expand the timer class docs and read about its properties and events.  can you see it will do what you want?  if you can't see that or you can't see how to use that info after you found it, you'll need to do more basic reading about how to use as3.