AS3 silent removechild: check if exist

sometimes you want to remove some children from the display list, but don’t know if the child exist or not!?

thanx to contains(), no probleme anymore;

[codesyntax lang="as3"]
if (this.contains(targetChild)) {
this.removeChild ( targetChild);
}
[/codesyntax]
another example
[codesyntax lang="as3"]
if (this.getChildByName(targetChild) != null) {
this.removeChild (this.getChildByName(targetChild));
}[/codesyntax]

a talk on AS3 functions

Default Values for Function Parameters
ActionSript 3 now allows you to specify default values for your function’s parameters. In doing so, that parameter then becomes optional and the default value assigned to the respective argument in the function call if a value is explicitly not provided.
You can only place parameters with default values after all required parameters.

function method(required:String, optional:String = “default”):void {
trace(required +” “+optional);
}
method(“Hello”); // “Hello default”


Calling Document Class functions from an imported class

the apply method

The Void

functions can return :void , :Number, :AnotherFunction

Class Scooping issue

The more I get advanced on learning AS3 the more hair I find on my keyboard :sc: !
here’s the deal;
i have a structure like this:
—- main.swf (this is my main flash swf)
—- main.as (this is my document class)
—- classes (folder containing other classes)
——— secondary.as (the class containing calls to functions on main.as)

main.as contains a function named tracer() :

TBC..

sending parameters to AS3 functions

passing vars to functions


function fun($vars:Object) {
this.vars = $vars;
this.vars.doo.apply(null, this.vars.what);
}
fun({doo:go, what:["salut"]});
function go(p:String) {
trace(p);
}

functions to URL/function  converter

var action:String="tracer";
if (action=="") {
//catch empty string
} else if (action.indexOf("http",0)!==0) {
//call a function, support for parameters in XML calls
var params:Array=action.split(",");
if (params.length>1) {
this[params[0]](params.slice(1,params.length));
} else {
this[params[0]]();
}
} else {//open the url
var ur:URLRequest=new URLRequest(action);
}//navigateToURL(ur,"_blank");