/**
* Copyright mezumona ( http://wonderfl.net/user/mezumona )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/zVgL
*/
// forked from bkzen's throw で条件分岐
/**
* 余り効率的ではなく、型も使えないですが…
*/
package
{
import flash.events.Event;
import flash.events.MouseEvent;
import com.actionscriptbible.Example;
/**
* switch true 式条件分岐
* @author jc at bkzen
*/
public class Test90 extends Example
{
private var cnt: uint;
public function Test90()
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e: Event = null): void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
//
trace("click");
stage.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(e:MouseEvent):void
{
const f:* = foo();
switch (true){
case f is String : trace("String ", f); break;
case f is int : trace("int", f); break;
case f is Error : trace("Error", f); break;
case f is Class : trace("Class", f); break;
case f is Object : trace("Object", f); break;
}
}
private function foo():*
{
switch (cnt++%5)
{
case 0:
return { "toString": function(): String { return "[MyObject]" }};
case 1:
return "'Error'";
case 2:
return 1234;
case 3:
return new Error("new Error");
case 4:
return Class;
}
}
}
}