Actionscript

i’ve learnt a little bit of c++ and was wondering if they were similar. the premade coding in normal mode is confusing to me, so is setup like c++ where theres a var section and a section where you declare them, then the actuall coding?

it can be a little hard to go from C++ to Actionscript, especially with the integration of the timeline and placement options of code.

First thing to suggest is getting out of normal mode in the AS editor and getting into advanced if you havent already (from the upper right menu). Here you can handcode the script and not type it in.

As far as ‘sections’ there really arent any. Everything in Flash is based on events, being either frame events, buttons events, or key events (etc). Everytime an event occurs, the script associated with that event is run.

This being the case, all kinds of function/variable declarations needed for the initialization of the movie are typically put in the first frame of the main timeline. From there, as soon as the movie starts and that frame is played by flash, the code is run and those definitions are set. From there, all code on other events can reference and use them.

For example, you can declare a function on the first frame of a flash movie like so:

function output(arg){
trace(arg);
}

and then on a button - script which is added to a button when that button is selected - you can call that function like:
on(press){
output(“button pressed”);
}

and in the event that you click that button, output(“button pressed”); is run and the function (having been defined when the movie passed through frame one which is immediately) is run and “button pressed” is displayed in the output window.

From there its just a matter of organizing code to do what you want when you want.

so how would i do, umm, like setting the variable “a” and having the user type something for the value of “a” and if it makes the statment true it will do something.

youd have to create a input textField in Flash, give it a Var value in the property panel (and/or an instance name) then associate whatever it is you are checking for with some action, probably a button action. So make a button and put on that button


on(release){
  if (a == "typed text"){
     // some action
  }
}

that was quick :slight_smile:
how do i make a textfield?

and what do i put in “some action”

lets say it will pop up a msg

with the text tool in flash

do you have msn messenger, it will be easier to talk

so i made a instance name for my input text field and its “a”
then this is my script for the button:

on (release){
if (a==“hello”){
output(“bye”);

}
}

so if hello is typed in the field then when i click the button the bye should come up, but its not working for me