by Daniel | Aug 26, 2008 | actionscript, Tools
Following up on an earlier post, here is the AS2.0 version of the dragToPosition X & Y coordinate tracer.
class com.sitedaniel.utils.Design
{
public static function dragToPosition(mc:MovieClip):Void
{
mc.onPress = function():Void
{
startDrag(this, false);
}
mc.onRelease = function():Void
{
this.stopDrag();
trace(this._x + ', ' + this._y);
}
}
}
by Daniel | Aug 26, 2008 | actionscript
This is an oldie but a goodie.
Getting around scope problems in AS2 can be a pain, but mx.utils.Delegate can help. The only problem is that you can’t pass parameters to your function using this one. The following class enables you to use the Delegate.create method, and also pass parameters to the function:
class com.sitedaniel.utils.Delegate
{
public static function create(t:Object, f:Function):Function
{
var _args:Array = arguments.slice(2);
var _func:Function = function():Void
{
var _newArgs:Array = arguments.concat(_args);
f.apply(t, _newArgs);
};
return _func;
}
}
UPDATE 11/10/08
This post gets quite a bit of traffic so I thought I should add a usage example.
This is a function that creates 5 buttons and spaces them in a loop:
private function _createButtons():Void {
for (var i:Number = 0; i<5; i++) {
var tmp:MovieClip = _mc.createEmptyMovieClip('b_'+i, i);
tmp._x = 40 * i;
tmp.onRelease = Delegate.create(this, _onRelease, i);
}
}
Delegate.create(this, _onRelease, i);
Then by passing 'i' in as a parameter, it comes into the function as an argument:
private function _onRelease(n:Number):Void {
trace('_onRelease : '+n)
}
You can also pass in multiple arguments, including different types:
tmp.onRelease = Delegate.create(this, _onRelease, i, true, {val:10});
...
function _onRelease(n:Number, isGood:Boolean, myObj:Object):Void {...
by Daniel | Jul 12, 2008 | actionscript
Here’s how to update the new Class template text in FlashDevelop.
Out of the box, if you hit Ctrl+1 you’ll get this:
/**
* ...
* @author Default
*/
class {
}
So that you don’t have to add in your name every time, you can edit the template here:
Tools -> Application Files…
Templates/ AS3.fdt (AS2.fdt)
You can add in your URL as well:
package $(CSLB){
/**
* ...
* @author Daniel
* @url http://www.sitedaniel.com
*/
public class $(EntryPoint) $(CSLB){
}
}
by Daniel | Jun 20, 2008 | actionscript
Recently I read that the best way to open pop-up windows from Flash was to use the ExternalInterface class. I found some code that looked good but it didn’t work in Safari on a Mac.
if (ExternalInterface.available) {
ExternalInterface.call("window.open",
"popup.html",
"win",
"height=300,
width=400,
toolbar=no,
scrollbars=yes");
} else {
getURL('popup.html', '_blank');
}
However it isn’t that hard to just use getURL and call a javascript function set in the html page:
//javascript
function openPopup() {
winWidth = 450;
winHeight = 680;
screenWidth = screen.availWidth;
screenHeight = screen.availHeight;
if (screenWidth < winWidth) {
winWidth = screenWidth;
}
if (screenHeight < winHeight) {
winHeight = screenHeight;
}
winTop = (screenHeight - winHeight) / 2;
winLeft = (screenWidth - winWidth) / 2;
window.open(\'page.html\',\'Title\',\'width=450,
height=680,scrollbars=no,
status=no,resizeable=yes\'+ \',
left=\' + winLeft + \',
top=\' + winTop);
//window.focus();
}
So far this works in all browsers.
by Daniel | May 19, 2008 | actionscript
This site is tucked away a little on vauxhall.co.uk but I really like it. There are a few hidden ‘application’ type sections that include a vehicle chooser and engine comparator.
link
Recent Comments