单击焦点管理员的按钮
我正在编写有关Arduino的应用程序,在MovieClip中,应用程序中有很多按钮。我可以使用键盘或鼠标单击任何一个,一切正常。但是该应用程序将使用数组中的控件。例如,如果数据[5] = 100,则应按下选项卡键盘按钮。如果数据[5] = 600,则应按Enter。目前,按TAB打开了Focusmanager。下次单击时,FocusManager移至下一个按钮。但是,如果数据[5] = 600,当我单击MovieClip中的按钮时,我会遇到错误。 3个按钮(BTN1,BTN2,BTN3)在主要阶段。 该代码运行良好,
this[BtnCurentName].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
3个按钮(BTN4,BTN5,BTN6)在MovieClip“ prop”内。我只能这样按下它们。
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中,以便我可以按下它?
I am writing an application for Arduino.There are a lot of buttons in the application that are in MovieClip. I can click on any one using the keyboard or mouse, everything works correctly. But the application will use control from the array. For example, if Data[5]=100, then the TAB keyboard button should be pressed. If Data[5]=600, then Enter should be pressed. At the moment, pressing TAB turns on the FocusManager. The next time you click, the FocusManager moves to the next button. But if Data[5]=600, when I click on the button that is in MovieClip, I get an error.
3 buttons (Btn1,Btn2,Btn3) are on the main stage.
This code works well
this[BtnCurentName].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
3 buttons (Btn4,Btn5,Btn6) are inside MovieClip "Prop".I can only press them like this.
this[BtnCurentName].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
This is my test code.
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
how can I determine in which MovieClip the button is located so that I can press it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
然后在您的
函数渲染
中可以检查:已解决。我得到了如此痕迹
Try:
Then in your
function Rendering
you can check as:Solved. I get such a trace