you can do two things to make this both more reusable, and increase performance.
var path:Object = _parent._parent;
var filters:Array;
switch (path.curr_chan)
{
case path.chan_one :
filters = path.filter1Array;
break;
case path.chan_two :
filters = path.filter2Array;
break;
case path.chan_three :
filters = path.filter3Array;
break;
}
path.churr_chan.filters = filters;
Here we are setting a path so that you don’t have to type it on every line… it’s pretty intuitive.
If/Else VS Switch
The one thing I wanted to remark on was the use of switch over if/else. Now if you look at the bytecode produced by an if/else and a switch that are doing the same thing, you’ll see that it is the exact same. With that said, switch will perform better than an if/else statement because if/else allows for values in it’s expression to change dynamically, which means that when the expression is evaluated the value may have to be retrieved from a location in memory, this process takes time. Now with switch statements the case is a predetermined value that is set at compile time… which means that the your expression is compared to a set value which does not need to be pulled out of memory.
I hope this made sense, if not please feel free to ask questions.
Here is a look at the actionscript vs bytecode comparison of if/else and case…
I will list both the if / else and the case, but I will only have one listing of bytecode, that is because when compiled they both share the same thing ;).
And please note that there is a difference between the two, and they are not always interchangable, and if used correctly one can have a performance benefit over the other.
On a side note, I am currently putting together a book proposal to send to O’reilly and FriendsOfEd…
Assuming that either are interested, this book’s focus is on efficiency and how to program Actionscript in a way that best fits the application you are working on. I go over a few topics that are very important for any programmer to know (especially us Actionscripters, due to Actionscripts complexes )…
Hopefully this all will work out I promise it will be more informative than I can be on the forums. Take Care.