我正在为Arduino.There编写一个应用程序,这个应用程序中有很多MovieClip中的按钮。我可以点击任何一个使用键盘或鼠标,一切正常工作。但是应用程序将使用来自数组的控件。例如,如果是Data5=100,那么应该按TAB键盘按钮。如果是Data5=600,则应按Enter。目前,按下TAB打开FocusManager。下一次单击时,FocusManager将移动到next按钮。但是如果Data5=600,当我单击MovieClip中的按钮时,我会得到一个错误。3个按钮(Btn1、Btn2、Btn3)处于主舞台。这段代码运行良好。
this[BtnCurentName].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));3个按钮(Btn4,Btn5,Btn6)在MovieClip中,"Prop".I只能按这样的按钮。
this[BtnCurentName].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));这是我的测试代码。
package
{
import flash.events.*;
import fl.managers.*;
import flash.display.*;
dynamic public class Main extends MovieClip
{
public var fm:FocusManager;
public var myBtnFocus:InteractiveObject;
public var myBtnName:String = "";
public var BtnCurentName:String = "";
public var Prop:MovieClip;
//# /////////////////////////////////////////////////////////////
//# Main code and supporting functions...
//# /////////////////////////////////////////////////////////////
public function Main()
{
addFrameScript(0, this.frame1);
fm = new FocusManager(this);
fm.setFocus( this ); //# manually set your button as default //# fm.setFocus( your button );
this.myBtnFocus = fm.getFocus(); //# update the reference to know currently focused
this.myBtnName = this.myBtnFocus.name; //# extract name from focused
}
public function Rendering() : void
{
this.Connect.Status.text = String( this.Data[5] ); // view arduino Data[5]
if (this.Data[5] > 0) //# if the button is pressed
{
if( ! Boolean(this.chkBtn))//# if the button is not pressed
{
//# press mouse click (Enter)
if ( this.Data[5] > 950 )
{
//# it works perfectly, BUT if my buttons are inside MovieClip, when pressing Data[5]=600 I get an error
//# TypeError: Error #1010: A term is undefined and has no properties.
trace (">> Name for Click is : " + BtnCurentName);
this[BtnCurentName].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
this.chkBtn = true;
/*
//# results of Trace...
>> Got TAB ... Focus is now changed to : Btn1
>> Name for Click is : Btn1
>> Got Click ... Button name is : Btn1
>> Got TAB ... Focus is now changed to : Btn2
>> Name for Click is : Btn2
>> Got Click ... Button name is : Btn2
>> Got TAB ... Focus is now changed to : Btn3
>> Name for Click is : Btn3
>> Got Click ... Button name is : Btn3
>> Got TAB ... with Parent ... Focus is now changed to : Prop.Btn4
>> Name for Click is : Prop.Btn4
TypeError: Error #1010: A term is undefined and has no properties.
//# end of results
*/
}
//# TAB = go to next button (component)
//# if ( (this.Data[5] == 100) || (this.Data[5] == "100") )
if ( this.Data[5] > 820 && this.Data[5] < 860 )
{
//# it works perfectly
this.myBtnFocus = fm.getNextFocusManagerComponent(); //# find it as next one
fm.setFocus( this.myBtnFocus ); //# then set as current selection (focused)
this.chkBtn = true;
}
}
}
else //# if the button is pressed and Data[5]==0, deleting variables
{
if( Boolean(this.chkBtn))
{
delete this.chkBtn;
}
}
return;
}
public function onMouseClick (event:MouseEvent = null) :void
{
if( event.currentTarget.name != null)
{ this.myBtnName = event.currentTarget.name; }
trace( ">> Got Click ... Button name is : " + this.myBtnName );
}
public function onFocusedBtn (event:FocusEvent) :void
{
if(event.target.parent.name == "root2")
{
BtnCurentName = String(event.target.name);
trace (">> Got TAB ... Focus is now changed to : " + BtnCurentName)
}
else
{
BtnCurentName = String(event.target.parent.name + '.' + event.target.name);
trace (">> Got TAB ... Focus is now changed to : " + BtnCurentName);
}
return;
}
function frame1()
{
this.Btn1.addEventListener( MouseEvent.CLICK, this.onMouseClick );
this.Btn2.addEventListener( MouseEvent.CLICK, this.onMouseClick );
this.Btn3.addEventListener( MouseEvent.CLICK, this.onMouseClick );
//# Buttons into MovieClip
this.Prop.Btn4.addEventListener( MouseEvent.CLICK, this.onMouseClick );
this.Prop.Btn5.addEventListener( MouseEvent.CLICK, this.onMouseClick );
this.Prop.Btn6.addEventListener( MouseEvent.CLICK, this.onMouseClick );
//# Focus listener
this.addEventListener( FocusEvent.FOCUS_IN, onFocusedBtn );
return;
}
} //end Class Main
} //end Package如何确定按钮位于哪个MovieClip中才能按下它?
发布于 2022-04-20 11:14:02
尝试:
public function onFocusedBtn (event:FocusEvent) :void
{
if(event.target.parent.name == "root2")
{
this.BtnParent = event.target.parent.name;
this.BtnName = event.target.name;
trace (">> Got TAB ... Focus is now changed to : " + this.BtnName)
}
else
{
this.BtnParent = event.target.parent.name;
this.BtnName = event.target.name;
trace (">> Got TAB ... with Parent ... Focus is now changed to : " + this.BtnParent + "." + this.BtnName);
}
return;
}然后,在您的function Rendering中,您可以检查如下:
//# press mouse click (Enter)
if ( this.Data[5] > 950 )
{
if(this.BtnParent == "root2")
{
trace (">> Name for Click is : " + this.BtnName);
this[this.BtnName].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
}
else
{
trace (">> Name for Click is : " + this.BtnParent + "." +this.BtnName);
this[this.BtnParent][this.BtnName].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
}
this.chkBtn = true;
} 解决了。我得到了这么多线索
>> Got TAB ... Focus is now changed to : Btn1
>> Name for Click is : Btn1
>> Got Click ... Button name is : Btn1
>> Got TAB ... Focus is now changed to : Btn2
>> Name for Click is : Btn2
>> Got Click ... Button name is : Btn2
>> Got TAB ... Focus is now changed to : Btn3
>> Name for Click is : Btn3
>> Got Click ... Button name is : Btn3
>> Got TAB ... with Parent ... Focus is now changed to : Prop.Btn4
>> Name for Click is : Prop.Btn4
>> Got Click ... Button name is : Btn4
>> Got TAB ... with Parent ... Focus is now changed to : Prop.Btn5
>> Name for Click is : Prop.Btn5
>> Got Click ... Button name is : Btn5
>> Got TAB ... with Parent ... Focus is now changed to : Prop.Btn6
>> Name for Click is : Prop.Btn6
>> Got Click ... Button name is : Btn6https://stackoverflow.com/questions/71900439
复制相似问题