Code+Snippets

Code to drag a control point and have situation adjust
//keeps track of whether the mouse is moving to drag the control point var beingDragged:Boolean = false;// keeps track of the position of the point from the last time the situation was adjusted var old_x, old_y:Number;

//create the drag point this._parent.attachMovie("ub_endpoint","dragpt_mc",this._parent.getNextHighestDepth); this._parent.dragpt_mc._visible = true; this._parent.dragpt_mc._x = x3; this._parent.dragpt_mc._y = y3;// create the event handler for when the control point is clicked this._parent.dragpt_mc.onPress = function { this.startDrag; beingDragged = true; old_x = this._x; old_y = this._y; . . . feedback_txt.htmlText = ""; }; //create the event handler for mouse movements this._parent.dragpt_mc.onMouseMove = function {// declare any local variables var … if (beingDragged) { //adjust the situation only if the control point is currently being dragged . . . old_x = this._x; old_y = this._y; } updateAfterEvent; };// create the event handler for when the control point is released this._parent.dragpt_mc.onRelease =this._parent.dragpt_mc.onReleaseOutside= function { this.stopDrag; updateAfterEvent; beingDragged = false; };

Code for an input box for a number
//give the input text box focus, so the user can type in it right away Selection.setFocus(sine_answer_txt);// select the entire contents of the field so that they will be replaced if the user starts typing Selection.setSelection(0,sine_answer_txt.length); check_btn._visible = false; feedback_txt.text = ""; . . . //Show the check button only when the input text box has changed sine_answer_txt.onChanged = function { check_btn._visible = true; };// If the user clicks the check button check_btn.onRelease = function { check_sine_answer(this); };

//If the user presses the Enter key _parent.keyListener.onKeyDown = function { if (Key.isDown(Key.ENTER)) { check_sine_answer(check_btn); } };// Check that the value supplied is okay function check_sine_answer(target:Object) { //give the field focus again since it might have lost it to the check button Selection.setFocus(sine_answer_txt); Selection.setSelection(0,sine_answer_txt.length);// Cast the value of the input box as a number var supplied_answer:Number = Number(sine_answer_txt.text); if (isNaN(supplied_answer)) { //not a number feedback_txt.text = "Please enter a valid number."; } else if (supplied_answer == correct_answer) { . . . } else . . . } } Key.addListener(_parent.keyListener);// In the parent declare the following: //var keyListener:Object = new Object;// so that the preceding line of code will work //You will have to remove the listener, once it is no longer wanted// in the parent use //Key.removeListener(keyListener);// in the child use // Key.removeListener(_parent.keyListener);