http://stackoverflow.com/questions/2459965/count-clicks-using-actionscript-3-0-in-flash
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d01.html
--------------------------------------------------------------------------------------------------------------------------
http://www.wsisley.co.uk/as3.shtml
https://www.youtube.com/watch?v=KTQp6rYK5XI
--------------------------------------------------------------------------------------------------------------------------
//Flash puts this first line in automatically
import flash.events.MouseEvent;
//declare the 3 variables
var a:Number;
var b:Number;
var c:Number;
//Add an Event Listener to the Button
button.addEventListener(MouseEvent.CLICK, calculate_fn);
// Function that multiplies the numbers together.
// Note the way that text has to be converted into a number
function calculate_fn(e:MouseEvent):void {
var a=Number(box_one.text)
var b=Number(box_two.text)
var c=a*b
//Convert the answer back into text using String
box_three.text=String(c)
}
http://www.parorrey.com/blog/flash-development/how-to-enabledisable-movieclips-as-buttons-in-flash-with-actionscript-3-0/
While working recently on a Flash AS3 project, I had a hard time setting up MovieClips as buttons and once I got MovieClips working as buttons, it took some time to figure out how to disable them as button or actually I should call it a clickable area in Action Script 3!
In the good old days of AS2, things were quite simple, were not they? Well you can still code in AS2 but since AS3 is latest version and especially from Flex development point of view, ActionScript 3.0 is the way to go.
In AS2, making MovieClips to act as buttons was much simpler and you must be familiar with the following code:
Enabling MovieClip as Button
Now in AS3, it becomes something like this:
Please note that in AS3, MovieClips no longer appear or behave as buttons even when they have listeners although they would work just fine when clicked or rolled over with mouse, you have to specifically enable the button mode for MovieClips to make them change cursor to hand:
Disabling MovieClip as Button
To disable the button completely, remove the listener for each event you want it to stop working and also disable the button mode for the MovieClip:
Example:
var myString:String = "7";
var myNumber = Number(myString);
The first line creates a string - myString with a value of 7. The second line takes that String data and passes it to the Number() constructor, which creates a number version from it. And the converted value, which is now of theNumber data type, is assigned to the variable named myNumber.The syntax would be:
Number(String)
Why would I want to convert strings to numbers in AS3?
Let's say you have some String data made up of numerical characters, and you'd like to perform arithmetic operations using that data. If you don't convert the strings to numbers, then Flash won't allow you to perform arithmetic operations on them.
Here's an example. Let's say we have 2 strings that are made up of numerical characters:
var s1:String = "2";
var s2:String = "5";
And then we try to multiply them:trace(s1 * s2);Flash is going to give us this error message:
1067: Implicit coercion of a value of type String to an unrelated type Number.
This error is telling us that we are trying to force (or coerce) the String data to be used as Number data. You can only multiply numbers, NOT strings. So in the act of trying to multiply String data, we are implicitly coercing the values to change into Number data. We can't do that. We should explicitly convert the String data to Number data first, and then perform the arithmetic operation.Here's another example. If we use the + operator on strings, then the strings will simply be joined together instead of the values being added to create a sum. Let's take a look:
var s1:String = "2";
var s2:String = "5";
trace(s1 + s2);
Here, we have two strings - s1 = "2" and s2 = "5". If we were to use the + operator on these two values, the result would be 25. The values of s1 (2) and s2 (5) will simply be joined together in the same way that letters are joined together in order to make words. If these were actual Number data, then the result of adding 2 and 5 would be 7instead.So if we want the values to be added to create a sum, then we'll need to use the Number() constructor to create number versions out of the strings:
var s1:String = "2";
var s2:String = "5";
trace( Number(s1) + Number(s2) );
Here, the strings s1 and s2 are each passed to the Number() constructor. This will create number versions from those strings, which can then be used in arithmetic operations. So here, the result will be 7, instead of the 25 we got from the previous example.Here's another similar example. If you'd like to use the contents of a TextField instance in arithmetic operations, then you will also need to use the Number() constructor to create number values from those numerical characters inside the text field. Remember that characters inside a TextField are of the String data type, which is why we'll need to convert them to the Number data type for usage in arithmetic operations. For example:
// Assume that tf1 and tf2 are instances of the TextField class
// and that they have already been created and added to the stage
tf1.text = "2";
tf2.text = "5";
trace( Number(tf1.text) + Number(tf2.text) );
So here, in the last line, we are retrieving the values inside the text fields (tf1 contains "2", tf2 contains "5"). Those values are passed to the Number() constructor which will create number versions from those values. Those numbers can then be used in the arithmetic operation. The result in this example would be 7.
EmoticonEmoticon