nth-child test
forked from flash on 2011-6-3 (diff: 28)
ActionScript3 source code
/**
* Copyright grapefrukt ( http://wonderfl.net/user/grapefrukt )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9ZK6
*/
// forked from grapefrukt's flash on 2011-6-3
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.events.Event;
import com.bit101.components.NumericStepper;
public class FlashTest extends Sprite {
private var tf:TextField;
private var ns_a:NumericStepper;
private var ns_b:NumericStepper;
public function FlashTest() {
tf = new TextField();
tf.defaultTextFormat = new TextFormat("_sans");
tf.height = 500;
tf.width = 500;
tf.x = 10;
tf.y = 30;
tf.selectable = false;
addChild(tf);
ns_a = new NumericStepper(this, 10, 10, redraw);
ns_b = new NumericStepper(this, 100, 10, redraw);
redraw();
}
public function redraw(e:Event = null):void {
tf.text = "";
for ( var i:int = 0; i < 40; i++){
trace(i + ":\t" + isNth(i, ns_a.value, ns_b.value));
}
}
public function isNth(index:int, a:int, b:int):Boolean {
return a < 0 ? (index - b < 0 && !((index - b) % a == 0)) : (index - b >= 0 && (index - b) % a == 0);
}
public function trace(t:*):void{
tf.appendText(t + "\n");
}
}
}
