Flexlib ScheduleViewer..如何处理项目的点击

发布于 2024-11-01 18:03:46 字数 734 浏览 0 评论 0原文

我正在尝试使用 flexlib 计划查看器 在我的应用程序中。

我希望拥有它,以便当我单击预定事件时,它会调用我的主应用程序中的一个函数(这将允许我编辑事件)。但似乎没有任何特定的功能可以用于类中内置的任何类似功能,即当我单击事件时不会调度任何事件。

我可以使用“单击”功能来检测该项目是否已被单击..并尝试过类似的操作:

         private function exerciseClickHandler(event:MouseEvent):void{
            if (exerciseSeries.selectedItem != null){
                //code

            }
        }

     <code:ScheduleViewer id="exerciseSeries" click="exerciseClickHandler(event)" />

此方法不是很可靠,因为如果它只在第一次工作..一旦选择了一个项目,它就会保持选中状态,因此对该项目的所有后续点击都满足条件。

有没有办法判断某个事件是否被点击?

或者我是否必须扩展组件并在单击事件时添加某种 clickEvent 。

I'm trying to use a flexlib schedule viewer in my application.

I want to have it so that when I click on a scheduled event, it calls a function in my main app (that will allow me to edit the event). But there doesn't seem to be any specific function for anything like this built into the class ie no event dispatched when I click on an event.

I can use the 'click' function to detect that the item has been clicked on.. and have tried something like this:

         private function exerciseClickHandler(event:MouseEvent):void{
            if (exerciseSeries.selectedItem != null){
                //code

            }
        }

     <code:ScheduleViewer id="exerciseSeries" click="exerciseClickHandler(event)" />

This method isn't very reliable because if it only works the first time.. once an item is selected, it stays selected so all following clicks on the item fulfills the condition.

Is there any way to determine whether an event was being clicked on?

Or do I have to extend the component and add some sort of clickEvent when an event is clicked on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

反话 2024-11-08 18:03:46

由于当您单击该组件时,exerciseClickHandler 就会启动,这行不通?

而不是

private function exerciseClickHandler(event:MouseEvent):void{
     if (exerciseSeries.selectedItem != null){
          //code
     }
}

private function exerciseClickHandler(event:MouseEvent):void{
     switch (exerciseSeries.selectedItem)
     {
          //code
          case xy:
          break;
     }
}

private function exerciseClickHandler(event:MouseEvent):void{
     //do something with exerciseSeries.selectedItem
}

我的意思是你写的是单击第一个元素后一切都会停止。根据您提供的代码,它必须停止,因为在第一次单击之后,exerciseSeries.selectedItem 将不再是 null,因为它已被选中。因此,删除您编写的条件并使用该实例。

Since exerciseClickHandler is firing up when you click on the component, wouldn't this work?

Instead of

private function exerciseClickHandler(event:MouseEvent):void{
     if (exerciseSeries.selectedItem != null){
          //code
     }
}

write

private function exerciseClickHandler(event:MouseEvent):void{
     switch (exerciseSeries.selectedItem)
     {
          //code
          case xy:
          break;
     }
}

or

private function exerciseClickHandler(event:MouseEvent):void{
     //do something with exerciseSeries.selectedItem
}

What I mean is that you wrote that everything stops after the first element is clicked. And according to the code you provided it has to stop, beacuse after the first click exerciseSeries.selectedItem won't be null anymore, since it's selected. So remove the conditional you wrote and use the instance.

雪花飘飘的天空 2024-11-08 18:03:46

我建议您设置一个 ChangeWatcher 来关注 selectedItem(或者 selectedItems,如果您打算在某个时候允许多重选择)。示例:

protected exerciseSeriesCreationCompleteHandler(event:FlexEvent):void{
   ChangeWatcher.watch(this,['exerciseSeries','selectedItem'], handleChange_SelectedItem);
}

protected function handleChange_SelectedItem(event:PropertyChangeEvent):void{
   // Either
   dispatchedEvent(//some custom event);
   // Or
   someDirectMethodCall();
}

另一种方法是每当用户单击时在鼠标坐标下的视图层次结构中搜索事件类的实例。

//Attach this click handler to the component

    private function handleClick(event : MouseEvent) : void {
        var obj : *EventClass*= null;
        var applicationStage : Stage = FlexGlobals.topLevelApplication.stage as Stage;

        var mousePoint : Point = new Point(applicationStage.mouseX, applicationStage.mouseY);
        var objects : Array = applicationStage.getObjectsUnderPoint(mousePoint);

        for (var i : int = objects.length - 1; i >= 0; i--) {
            if (objects[i] is *EventClass*) { 
                obj = objects[i] as *EventClass*;
                break;
            }
        }

   if(obj is *EventClass*){
      //Dispatch some custom event with obj being the item that was clicked on.
   }
}

其中 EventClass 是表示事件的对象的类

I'd suggest you set up a ChangeWatcher to keep an eye on the selectedItem (or selectedItems if you are going to allow multiple selection at some point). Example:

protected exerciseSeriesCreationCompleteHandler(event:FlexEvent):void{
   ChangeWatcher.watch(this,['exerciseSeries','selectedItem'], handleChange_SelectedItem);
}

protected function handleChange_SelectedItem(event:PropertyChangeEvent):void{
   // Either
   dispatchedEvent(//some custom event);
   // Or
   someDirectMethodCall();
}

An alternative would be to search for an instance of the the event class in the view hierarchy under the mouse coordinates whenever a user clicks.

//Attach this click handler to the component

    private function handleClick(event : MouseEvent) : void {
        var obj : *EventClass*= null;
        var applicationStage : Stage = FlexGlobals.topLevelApplication.stage as Stage;

        var mousePoint : Point = new Point(applicationStage.mouseX, applicationStage.mouseY);
        var objects : Array = applicationStage.getObjectsUnderPoint(mousePoint);

        for (var i : int = objects.length - 1; i >= 0; i--) {
            if (objects[i] is *EventClass*) { 
                obj = objects[i] as *EventClass*;
                break;
            }
        }

   if(obj is *EventClass*){
      //Dispatch some custom event with obj being the item that was clicked on.
   }
}

Where EventClass is the class of the objects that represent events

无名指的心愿 2024-11-08 18:03:46

我也遇到过类似的问题,有时您可以通过用 Box 包装对象并将单击事件放在 Box 上来解决。如果您还没有尝试过,这是一个便宜且简单的解决方案(如果它适合您)。

<mx:Box click="exerciseClickHandler(event)">
 <code:ScheduleViewer id="exerciseSeries"  />
</mx:Box>

I have had similar problems and sometimes you can get by with wrapping the object with a Box and putting the click event on the Box. If you have not already tried that, it's a cheap, easy fix (if it works for you).

<mx:Box click="exerciseClickHandler(event)">
 <code:ScheduleViewer id="exerciseSeries"  />
</mx:Box>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文