http://blog.pixelbreaker.com/actionscript-3-0/as30-reversed-for-loop
Nuff said.
A diary about programming problems - to help me more easily learn from (and Google) past mistakes.
Friday, 13 September 2013
Tuesday, 10 September 2013
Easy - Get REAL Co-ordinates of a Movieclip Inside a Movieclip: localToGlobal, AS3
localToGlobal allows you to get the actual position of a movie clip, that is inside another movieclip.
Normally, if you trace, or try to get, the x or y coordinate of a movie clip, you will get its position, relative to the 0,0 coordinates of the movie clip it is sitting in. These are the local coordinates of the child movieclip.
To get the global coordinates, ie, where it REALLY is on the main stage, you need points, and the localToGlobal function.
e.g
(On the stage, there is a squareHole_mc, and inside that is a roundPeg_mc.)
var pt:Point = new Point(squareHole_mc.roundPeg_mc.x,squareHole_mc.roundPeg_mc.y);
pt = squareHole.localToGlobal(pt);
So basically, you create a Point, that contains the local x and y coordinates you are interested in. Then you use localToGlobal to find out the global version of those coordinates, bearing in mind they are sitting in a parent movieclip.
UPDATE:
Now in one line(!!!):
var pt:Point = sqH.localToGlobal(new Point(sqH.rPeg.x,sqH.rPeg.y));
Normally, if you trace, or try to get, the x or y coordinate of a movie clip, you will get its position, relative to the 0,0 coordinates of the movie clip it is sitting in. These are the local coordinates of the child movieclip.
To get the global coordinates, ie, where it REALLY is on the main stage, you need points, and the localToGlobal function.
e.g
(On the stage, there is a squareHole_mc, and inside that is a roundPeg_mc.)
var pt:Point = new Point(squareHole_mc.roundPeg_mc.x,squareHole_mc.roundPeg_mc.y);
pt = squareHole.localToGlobal(pt);
So basically, you create a Point, that contains the local x and y coordinates you are interested in. Then you use localToGlobal to find out the global version of those coordinates, bearing in mind they are sitting in a parent movieclip.
UPDATE:
Now in one line(!!!):
var pt:Point = sqH.localToGlobal(new Point(sqH.rPeg.x,sqH.rPeg.y));
Monday, 9 September 2013
Losing Focus on Textfield, AS3
I had a problem with a text field, I wanted to click on it, have something happen, and be able to continue typing straight away, but it kept losing focus after the first letter.
So I added a trace statement to find out what was happening, and then it would lose focus after it was clicked.
The reason was the trace statement was causing the whole swf to lose focus. So I am sending a trace statement in the frame, so that the initial focus is dealt with. The losing of focus doesn't occur after the first trace statement.
P.S. To set focus using action script:
stage.focus = textfield_txt;
textfield_txt.setSelection(textfield_txt.length,textfield_txt.length);
So I added a trace statement to find out what was happening, and then it would lose focus after it was clicked.
The reason was the trace statement was causing the whole swf to lose focus. So I am sending a trace statement in the frame, so that the initial focus is dealt with. The losing of focus doesn't occur after the first trace statement.
P.S. To set focus using action script:
stage.focus = textfield_txt;
textfield_txt.setSelection(textfield_txt.length,textfield_txt.length);
Subscribe to:
Posts (Atom)