单击焦点管理员的按钮

发布于 2025-01-22 00:06:08 字数 6197 浏览 2 评论 0原文

我正在编写有关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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒江雪… 2025-01-29 00:06:08

尝试:

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;
}

然后在您的函数渲染中可以检查:

//# 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 : Btn6

Try:

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;
}

Then in your function Rendering you can check as:

//# 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;

} 

Solved. I get such a 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
>> 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 : Btn6

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文