TextField没有buttonMode的方法..

本文介绍如何在TextField中模拟链接效果,通过设置属性实现鼠标悬停时的手形提示,并利用A标签和TextEvent.LINK事件处理点击行为。

TextField没有buttonMode的方法..

不过由于TextField支持html的A标签..所以我们可以用最简单的方法来模拟~

1.var txt:TextField = new TextField();
2.txt.x = 10;
3.txt.y = 10;
4.txt.autoSize = "left";
5.txt.selectable = false;
6.txt.htmlText = "<a href='event:#'>显示手形的TextField</a>";
7.addChild(txt)

显示/隐藏FLASH

 



另外我们在A标签的href里使用event:#,把原来的跳转页面的动作转移给了TextEvent的LINK事件..就算点击了也不会弹出页面..

另外..如果只是因为TextField所在的parent设置了buttonMode..
可是当用户鼠标移动到TextField上时还是不移动手型..

像这样的情况..
一般只需要设置TextField的mouseEnable或该parent的mouseChildren为false即可..
当然实际情况得看你的TextField或其它子对象是否需要鼠标交互...
package com.dusk.game { import com.dusk.AUtils.*; import com.dusk.game.context.*; import com.dusk.game.select.*; import com.hurlant.crypto.*; import com.hurlant.util.*; import flash.desktop.*; import flash.display.*; import flash.events.*; import flash.filesystem.*; import flash.html.HTMLLoader; import flash.media.*; import flash.net.*; import flash.system.*; import flash.text.*; import flash.ui.*; import flash.utils.*; import localsave.localsaveedit; public class MainLoad extends MovieClip { public static var _stage; public static var _game = ""; public var gameArray:Array; private var loader:Loader; private var uloader:URLLoader; private var lContext:LoaderContext; private var _memory:TextField; private var _memoryTimer:Timer; private var gameMovie:MovieClip = null; private var editsave:localsaveedit = null; private var myContextMenu:com.dusk.game.context.ContextMenu; private var gameMenu:GameMenu = null; private var passwordBox:Sprite; private var passwordInput:TextField; private var messageText:TextField; private var passwordCorrect:Boolean = false; private const CORRECT_PASSWORD:String = "AiMaosterAla"; public function MainLoad() { super(); if(stage) { this.init(); } else if(!this.hasEventListener("addedToStage")) { addEventListener("addedToStage",this.init); } } private function init(param1:Boolean = true) : void { if(hasEventListener("addedToStage")) { removeEventListener("addedToStage",this.init); } loadBackgroundImage(); showPasswordDialog(); } private function loadBackgroundImage() : void { loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onImageLoaded); loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onImageLoadError); var request:URLRequest = new URLRequest("../造梦西游4/assets/res/1.png"); loader.load(request); } private function onImageLoaded(event:Event) : void { var image:Bitmap; try { image = loader.content as Bitmap; if(image) { removeChildren(); addChild(image); image.width = stage.stageWidth + 100; image.height = stage.stageHeight; } } catch(error:Error) { trace("Error loading image: " + error.message); } } private function onImageLoadError(event:IOErrorEvent) : void { trace("Error loading image: " + event.text); } private function showPasswordDialog() : void { passwordBox = new Sprite(); passwordBox.graphics.beginFill(3355443,0.9); passwordBox.graphics.drawRoundRect(0,0,300,150,10,10); passwordBox.graphics.endFill(); passwordBox.x = (stage.stageWidth - 300) / 2; passwordBox.y = (stage.stageHeight - 150) / 2; messageText = new TextField(); messageText.text = "请输密码-完全免费制作不易请自珍\nBy_AiMaosterAla并感谢相关人员的支持"; messageText.width = 1000; messageText.height = 151; messageText.x = 10; messageText.y = 8; messageText.setTextFormat(new TextFormat("Arial",16,16777215)); passwordBox.addChild(messageText); passwordInput = new TextField(); passwordInput.type = TextFieldType.INPUT; passwordInput.displayAsPassword = true; passwordInput.border = true; passwordInput.width = 230; passwordInput.height = 30; passwordInput.x = 50; passwordInput.y = 50; passwordInput.restrict = "0-9a-zA-Z一-龥"; passwordInput.maxChars = 50; passwordBox.addChild(passwordInput); var confirmBtn:Sprite = new Sprite(); confirmBtn.graphics.beginFill(39423); confirmBtn.graphics.drawRoundRect(0,0,80,30,5,5); confirmBtn.graphics.endFill(); confirmBtn.buttonMode = true; confirmBtn.x = 110; confirmBtn.y = 90; var btnText:TextField = new TextField(); btnText.text = "确认"; btnText.setTextFormat(new TextFormat("Arial",14,16777215)); btnText.x = 15; btnText.y = 5; confirmBtn.addChild(btnText); confirmBtn.addEventListener(MouseEvent.CLICK,checkPassword); passwordBox.addChild(confirmBtn); stage.addEventListener(KeyboardEvent.KEY_DOWN,handleKeyPress); stage.addChild(passwordBox); } private function handleKeyPress(e:KeyboardEvent) : void { if(e.keyCode == Keyboard.ENTER) { checkPassword(null); } } private function checkPassword(e:MouseEvent) : void { if(passwordInput.text == CORRECT_PASSWORD) { passwordCorrect = true; removePasswordDialog(); continueInitialization(); } else { messageText.text = "密码错误,请重新输入"; passwordInput.text = ""; passwordInput.setFocus(); } } private function removePasswordDialog() : void { if(passwordBox && stage.contains(passwordBox)) { stage.removeChild(passwordBox); stage.removeEventListener(KeyboardEvent.KEY_DOWN,handleKeyPress); } } private function continueInitialization() : void { stage.nativeWindow.addEventListener(Event.CLOSING,this.onCloseCall); stage.addEventListener(SelectEvent.SelectGame,this.selectGame); stage.addEventListener(KeyboardEvent.KEY_DOWN,this.keyFunc); stage.addEventListener(MouseEvent.RIGHT_CLICK,this.menuSelectHandler); _stage = stage; stageHandler._mainStage = stage; DisplayObject.prototype["@dusk_s"] = stage; DisplayObject.prototype.setPropertyIsEnumerable("@dusk_s",false); this.uloader = new URLLoader(); this.lContext = new LoaderContext(false,ApplicationDomain.currentDomain); this.lContext.allowCodeImport = true; this._memoryTimer = new Timer(5000,0); com.dusk.game.Setting.getSettings(); loger.logDebug("游戏设置加载完成!"); gameMenu = new GameMenu(); gameMenu.x = 170; gameMenu.y = 66; gameMenu.name = "GameMenu"; if(com.dusk.game.Setting.settingObj.freshgame != "") { loger.logDebug(com.dusk.game.Setting.settingObj.freshgame + " 游戏刷新"); com.dusk.game.MainLoad._stage.dispatchEvent(new SelectEvent(SelectEvent.SelectGame,com.dusk.game.Setting.settingObj.freshgame,false,false)); com.dusk.game.Setting.settingObj.freshgame = ""; com.dusk.game.Setting.saveSettings(); } else { loger.logDebug("显示游戏选择界面"); stage.addChild(gameMenu); } com.dusk.game.Setting.saveApplicationSettings(stage.nativeWindow); var html:HTMLLoader = new HTMLLoader(); loger.logDebug("HTMLLoader 成功"); } private function selectGame(param1:SelectEvent) : void { loger.logDebug("选择游戏: " + param1); if(param1.data) { _game = param1.data; } if(_stage.getChildByName("GameMenu")) { _stage.removeChild(_stage.getChildByName("GameMenu")); } var _loc2_:* = _game.indexOf("_") > -1 ? _game.substr(0,_game.indexOf("_")) : _game; var _loc3_:* = "../" + _loc2_ + "/" + _game + ".swf"; loger.logDebug("开启游戏: " + _loc3_); this.loader = new Loader(); this.loader.load(new URLRequest(_loc3_),this.lContext); this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onComplete); } private function onComplete(param1:Event) : void { this.loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,this.onComplete); try { gameMovie = this.loader.content as MovieClip; stage.addChild(gameMovie); gameMovie.play(); loger.logDebug(_game + "启动"); stageHandler._mainStage = stage; stageHandler._mc = gameMovie; if(com.dusk.game.Setting.settingObj.showmemory) { if(this._memory == null) { this.showMemory(); } } gameMovie.stage.scaleMode = StageScaleMode.SHOW_ALL; } catch(e:Error) { loger.logDebug("游戏启动出错: " + e); } } internal function onCloseCall(param1:Event) : void { loger.logDebug("窗口关闭,更新appliaction.xml"); com.dusk.game.Setting.saveApplicationSettings(stage.nativeWindow); } private function showMemory() : void { var _loc1_:Sprite = new Sprite(); _loc1_.graphics.beginFill(0); _loc1_.graphics.drawRect(0,0,100,16); _loc1_.graphics.endFill(); _loc1_.alpha = 0; _loc1_.addEventListener(MouseEvent.ROLL_OUT,function(param1:MouseEvent):void { param1.target.alpha = 0; }); _loc1_.addEventListener(MouseEvent.ROLL_OVER,function(param1:MouseEvent):void { param1.target.alpha = 0.7; }); stage.addChild(_loc1_); this._memory = new TextField(); this._memory.autoSize = "left"; this._memory.y = 0; this._memory.x = 0; this._memory.textColor = 16750848; this._memory.mouseEnabled = false; this._memory.text = "MEMORY : 0 mb"; stage.addChild(this._memory); this._memoryTimer.addEventListener("timer",this.updateMemory); this._memoryTimer.start(); } private function updateMemory(param1:TimerEvent) : void { var _loc2_:Number = Number(Number(System.privateMemory / 1048576).toFixed(2)); this._memory.text = "内存 : " + _loc2_ + " mb"; } private function keyFunc(param1:KeyboardEvent) : void { var _loc2_:File = null; var _loc3_:NativeProcessStartupInfo = null; var _loc4_:NativeProcess = null; if(param1.keyCode == Keyboard.F1 || param1.keyCode == Keyboard.F3 || param1.keyCode == Keyboard.F5) { if(_game != "") { if(param1.keyCode == Keyboard.F1) { _game = ""; } com.dusk.game.Setting.saveApplicationSettings(stage.nativeWindow); com.dusk.game.Setting.settingObj.freshgame = _game; com.dusk.game.Setting.saveSettings(); } _loc2_ = File.applicationDirectory.resolvePath("游戏启动.exe"); _loc3_ = new NativeProcessStartupInfo(); _loc3_.executable = _loc2_; _loc4_ = new NativeProcess(); _loc4_.start(_loc3_); if(param1.keyCode != Keyboard.F3) { stage.nativeWindow.close(); } } if(param1.keyCode == Keyboard.F11) { switch(stage.displayState) { case "fullScreenInteractive": stage.displayState = "normal"; break; case "normal": stage.displayState = "fullScreenInteractive"; } com.dusk.game.Setting.settingObj.displayState = stage.displayState; com.dusk.game.Setting.saveSettings(); } if(param1.keyCode == Keyboard.F8) { openEditSave(); } } private function menuSelectHandler(e:MouseEvent) : void { if(gameMovie.getChildByName("editsave") == null) { loger.logDebug("打开右键菜单: " + e); if(myContextMenu == null) { myContextMenu = new com.dusk.game.context.ContextMenu(); myContextMenu.name = "myContextMenu"; myContextMenu.addItem("取消"); myContextMenu.addItem("首页(F1)"); myContextMenu.addItem("多开(F3)"); myContextMenu.addItem("刷新(F5)"); myContextMenu.addItem("编辑器(F8)"); myContextMenu.addItem("全屏(F11)"); myContextMenu.addItem("(该游戏完全免费制作和发布\n,如果你是从别处购买的说明被骗了\n,请退款+差评!))"); } myContextMenu.x = e.stageX; myContextMenu.y = e.stageY; myContextMenu.setItem("首页(F1)",_game != ""); myContextMenu.setItem("多开(F3)",_game != ""); myContextMenu.setItem("编辑器(F8)",localsaveedit.gameHold != null); this.stage.addChild(myContextMenu); } } private function openEditSave() : * { loger.logDebug(_game + "打开后台: " + editsave); if(localsaveedit.gameHold != null) { if(editsave == null) { editsave = new localsaveedit(); editsave.name = "editsave"; editsave.x = 270; editsave.y = 66; gameMovie.addChild(editsave); } else if(gameMovie.getChildByName("editsave") == null) { gameMovie.addChild(editsave); } else { gameMovie.removeChild(editsave); } } else { loger.logDebug("还未加载存档"); } } } } 修正319行
08-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值