flash on 2015-3-23
♥0 |
Line 78 |
Modified 2015-03-23 11:39:50 |
MIT License
archived:2017-03-20 01:57:57
ActionScript3 source code
/**
* Copyright Cheshir ( http://wonderfl.net/user/Cheshir )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lnNA
*/
package {
import flash.events.MouseEvent;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var tut:Tutorial;
public function FlashTest() {
// write as3 code here..
tut = new Tutorial("Some text will be placed");
addChild(tut);
// tut.style = 'bottom';
tut.style = 'top';
// tut.style = 'left';
// tut.style = 'right';
tut.field = stage.getRect(stage);
stage.addEventListener(MouseEvent.MOUSE_MOVE, changeTarget);
}
private function changeTarget(e:MouseEvent):void{
tut.tx = mouseX;
tut.ty = mouseY;
}
}
}
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.text.TextField;
import flash.display.Sprite;
Class {
class Tutorial extends Sprite {
private var tf:TextField = new TextField();
private var canvas:Sprite = new Sprite();
private var targetX:Number = 0;
private var targetY:Number = 0;
private var conectPoint:Point = new Point();
private var field:Rectangle;
public function Tutorial(text:String){
tf.mouseEnabled = false;
tf.autoSize = 'left';
tf.text = text;
addChild(canvas);
addChild(tf);
redrawCanvas();
}
private function redrawCanvas(color:uint=0xCCCCCC):void{
canvas.graphics.clear();
canvas.graphics.beginFill(color);
canvas.graphics.drawRect(tf.x-5, tf.y-5, tf.width+10, tf.height+10);
canvas.graphics.lineStyle(2, color);
canvas.graphics.moveTo(conectPoint.x, conectPoint.y);
canvas.graphics.lineTo(canvas.width/2, canvas.height/2);
}
public function set field(val:Rectangle):void{
this.field = field;
}
public function set style(val:String):void{
if(val=='bottom'){
conectPoint.x = canvas.width/2;
conectPoint.y = -15;
}
if(val=='top'){
conectPoint.x = canvas.width/2;
conectPoint.y = 5 + canvas.height;
}
if(val=='left'){
conectPoint.x = -15;
conectPoint.y = canvas.height/2;
}
if(val=='right'){
conectPoint.x = 5 + canvas.width;
conectPoint.y = canvas.height/2;
}
redrawCanvas();
}
public function set tx(val:Number):void{
this.targetX = val;
this.x = targetX-conectPoint.x;
}
public function set ty(val:Number):void{
this.targetY = val;
this.y = targetY-conectPoint.y;
}
}
}