Tool Tip

Bước 1: Khởi tạo class “ToolTip.as” trong thư mục “com”

CODE:

package com {
import flash.display.MovieClip;

import gs.TweenMax;

import flash.events.Event;
import flash.text.AntiAliasType;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextField;

/**
* @author yoko
*/
public class ToolTip extends MovieClip {
private var BG_COLOR : uint;
private var TEXT_COLOR : uint;
private var TEXT_SIZE : int;
private var FONT : String;
private var TOOL_TEXT : String;

private var field_txt : TextField;

private var ratio : int = 10;

private var holder_mc : MovieClip;
private var bg_mc : MovieClip;
private var father : MovieClip;

private var left_point : Number;
private var top_point : Number;
private var right_point : Number;
private var bottom_point : Number;

public function ToolTip(BG_COLORS : int,TEXT_COLORS : int,TEXT_SIZES : int,FONTS : String,CONTENT : String) {
BG_COLOR = BG_COLORS;
TEXT_COLOR = TEXT_COLORS;
TEXT_SIZE = TEXT_SIZES;
FONT = FONTS;
TOOL_TEXT = CONTENT;

addEventListener(Event.ADDED_TO_STAGE, init);

mouseEnabled = false;
alpha = 0;
}

private function init(evt : Event) : void {
removeEventListener(Event.ADDED_TO_STAGE, init);

father = parent as MovieClip;

left_point = 0;
top_point = 0;
right_point = stage.stageWidth;
bottom_point = stage.stageHeight;

createHolder();
createTextField();
createBackground();
fixPosition();
fadeIn();
addEventListener(Event.ENTER_FRAME, addMovement);
}

private function createHolder() : void {
holder_mc = new MovieClip();
addChild(holder_mc);
}

private function createTextField() : void {
field_txt = new TextField();
field_txt.multiline = true;
field_txt.selectable = false;
//field_txt.embedFonts = true;
field_txt.antiAliasType = AntiAliasType.ADVANCED;
field_txt.autoSize = TextFieldAutoSize.LEFT;
field_txt.defaultTextFormat = getFormat();
field_txt.htmlText = TOOL_TEXT + “  “;
field_txt.width = field_txt.textWidth + 10;
field_txt.height = field_txt.textHeight + 20;
holder_mc.addChild(field_txt);
}

private function getFormat() : TextFormat {
var format : TextFormat = new TextFormat();
format.font = FONT;
format.size = TEXT_SIZE;
format.color = TEXT_COLOR;
return format;
}

private function createBackground() : void {
bg_mc = new MovieClip();
bg_mc.graphics.beginFill(BG_COLOR, 1);
bg_mc.graphics.drawRoundRect(-ratio, -ratio, field_txt.width + ratio * 2, field_txt.height + ratio * 2, ratio, ratio);
holder_mc.addChild(bg_mc);

holder_mc.swapChildren(field_txt, bg_mc);
}

private function fixPosition() : void {
if (father.mouseX < stage.stageWidth / 2) {
x = father.mouseX;
} else {
x = father.mouseX – width;
}
if (father.mouseY < stage.stageHeight / 2) {
y = father.mouseY + height – ratio * 2;
} else {
y = father.mouseY – height;
}
}

private function fadeIn() : void {
TweenMax.to(this, 0.5, {alpha:0.5});
}

private function addMovement(evt : Event) : void {
if (father.mouseX < stage.stageWidth / 2) {
x = father.mouseX;
} else {
x = father.mouseX – width + ratio * 2;
}
if (father.mouseY < stage.stageHeight / 2) {
y = father.mouseY + height – ratio * 2;
} else {
y = father.mouseY – height;
}
if (x > stage.stageWidth – width) {
x = stage.stageWidth – width;
}
if (x < ratio * 2) {
x = ratio * 2;
}
}

public function destroy() : void {
removeEventListener(Event.ENTER_FRAME, addMovement);
father.removeChild(this);
}
}
// end
}

Bước 2: Khởi tạo class “MainToolTip.as” trong thư mục “com” để sử dụng

CODE:

package com {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;

/**
* @author yoko
*/
public class MainToolTip {
private var TOOLTIP : ToolTip;
private var ROOT : MovieClip;
private var BUTTON : MovieClip;

public function MainToolTip(mainTimeline : MovieClip) {
ROOT = mainTimeline;
BUTTON = ROOT.clip_mc;

BUTTON.addEventListener(MouseEvent.MOUSE_OVER, manageMouseOver);
BUTTON.addEventListener(MouseEvent.MOUSE_OUT, manageMouseOut);
}

private function manageMouseOver(evt : Event) : void {
TOOLTIP = new ToolTip(0×000000, 0xFFFF00, 12, “Arial”, “<b>ToolTip</b>\nHello VNFX.COM”);
ROOT.addChild(TOOLTIP);
}

private function manageMouseOut(evt : Event) : void {
if(TOOLTIP != null) {
TOOLTIP.destroy();
TOOLTIP = null;
}
}
}
// end
}

Bước 3:

_ Tạo FLA Document “Tooltip.fla”

_ Tạo 1 movieClip “clip_mc”

_ Frame 1 mở bảng actionScript

CODE:

import com.MainToolTip;
new MainToolTip(this);

_ Lưu lại và chạy thử

Có mộ phản hồi tới “Tool Tip”

  1. Hieu nói:

    Sao tui lam nhu vay ma ko chay ji het


Gửi phản hồi

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Thay đổi )

Twitter picture

You are commenting using your Twitter account. Log Out / Thay đổi )

Facebook photo

You are commenting using your Facebook account. Log Out / Thay đổi )

Connecting to %s

Follow

Get every new post delivered to your Inbox.