0

这是as3:

import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequestMethod;
import flash.events.Event;
import flash.display.MovieClip;


wheeler.guide.visible = false;
center.addEventListener(MouseEvent.CLICK, rotateHorizontal);

Stop_mc.addEventListener(MouseEvent.CLICK, stopspin);

function rotateHorizontal(e:MouseEvent):void
{
    stage.addEventListener(Event.ENTER_FRAME,spinner);

}

var mcbtn:MovieClip;
var prizes:Array = new Array(0,180,0,40,30,0,80,75,0,10,0,25,120,0);
var prizewon:int;

for (var i:int=0; i<14; ++i)
{
    mcbtn = wheeler["btn" + (i + 1)];

    if (! mcbtn || ! prizes[i])
    {
        continue;
    }

    mcbtn.txt.text = "Earn " + String(prizes[i]) + " messages";
}

function spinner(e:Event)
{
    wheeler.rotationZ +=  15;
    pointer_txt.text = " ";

    if (wheeler.rotationZ > 360)
    {
        wheeler.rotationZ = wheeler.rotationZ - 360;
    }
    //trace(wheeler.rotationZ);
}

function completed(event:Event):void
{
    if (event.target.data.success == "true")
    {
        trace("Completed");
    }
}

function stopspin(e:Event):void
{
    var txt:String;
    stage.removeEventListener(Event.ENTER_FRAME,spinner);
    prizewon = -1;
    prizewon = (14 - Math.floor(wheeler.rotationZ / (360 / 14)));

    if (prizes[prizewon - 1])
    {
        txt = "You have earned " + prizes[prizewon - 1] + " Messages";
    }
    else
    {
        txt = "You have earned no Messages";
    }

    pointer_txt.text = txt;

    var phpVar:URLVariables = new URLVariables();
    phpVar.code_txt = code_txt.text;
    phpVar.name_txt = name_txt.text;
    phpVar.phone = phone_txt.text;
    phpVar.Result = pointer_txt.text;
    var phpLoader:URLLoader = new URLLoader(phpFileRequest);
    var phpFileRequest:URLRequest = new

 URLRequest("http://localhost/spin_webapp/deposit.php");
    phpFileRequest.method = URLRequestMethod.POST;
    phpFileRequest.data = phpVar;
    phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

    phpLoader.addEventListener(Event.COMPLETE,completed);
    phpLoader.load(phpFileRequest);
}
4

1 回答 1

0

您需要创建一个事件来处理文本字段上的按键。

每当按键发生时,按键事件处理函数将检查文本字段是否为 NULL 或执行其他验证。如果一切正常,则设置一个标志,如name_txt__valid=TRUE.

然后 if name_txt__valid, phone_txt__valid and pointer_txt__validall are TRUEthen make themovieclip button可见,否则隐藏它。

显然,必须通知用户文本字段有效/有效,否则他们不会意识到按钮消失的原因。


更新:

抱歉,我现在无法测试下面的代码,但下面应该更好地详细说明我认为需要做的事情..

在初始化期间创建监听器的语法: 例如。

name_txt.addEventListener(Event.CHANGE,name_txt_ChangeListener);
//Also lets initialize our flags...
name_txt__valid=false;
phone_txt__valid=false;
pointer_txt__valid=false;
center.enabled = false;

参考:AddchangeeventtoTextField

然后只需添加验证逻辑:

private function name_txt_ChangeListener (e:Event):void {
...
  trace("Text field event triggered");
  //Check if text is null or invalid
  //If valid then set a flag like name_txt__valid=TRUE
  if (name_txt.text == "") {
     name_txt__valid=false;      
  } else {
     name_txt__valid=true;      
  }

  //Then make a function call to decide whether to show/hide the center button.
  showHideCenterButton();
...
}

function showHideCenterButton(){
...
  //If  name_txt__valid, phone_txt__valid and pointer_txt__valid, 
  // all are TRUE then enable the button. Else disable it like center.enabled = false;
  if( (name_txt__valid==true) &&
      (phone_txt__valid==true) &&
      (pointer_txt__valid==true)
    ) {
       center.enabled = true;
    } else {
       center.enabled = false;
    }
...
}
于 2012-12-13T10:26:11.263 回答