AS3 OOP可视化逻辑 - 链接过滤器和数据源
我正在尝试在 ActionScript 3.0 中可视化测验的结果。
我想要一些输入的是如何以灵活的 OOP 方式最好地将“过滤器”(附图中的右上角)链接到数据源。
结果数组现在包含正确答案的数量和有关参加测验的人的元数据。元数据可以是离散的(性别)或连续的(年龄)。
结果 = [{姓名:“丽莎”,正确:5,性别:0,年龄:52},{姓名:“彼得”,正确:3,性别:1,年龄:32} ... ]
我怎么知道例如,当我更换过滤器时,盒子会改变颜色? 每个盒子对象是否应该保存自己的数据,或者是否应该有某种控制器监听过滤器对象以分派事件,然后调用 box.setColor 方法? 我有什么选择?
I'm trying to visualize the results of a quiz in ActionScript 3.0.
What I would like some input on is how to best link the "filters" (top right corner in attached image) to the data source in a flexible OOP way.
The result array now contains both number of correct answers and meta data about the person taking the quiz. The meta data could be both discrete (sex) or continuous (age).
results = [{name: "Lisa", correct: 5, sex: 0, age: 52}, {name: "Peter", correct: 3, sex: 1, age: 32} ... ]
How do I tell the boxes to, for example, change color when I change filter?
Should each box object hold its own data or should there be some sort of controller listening to the filter object to dispatch an event and thereafter call a box.setColor method?
What are my options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为总体想法是让事情尽可能灵活,今天你想使用盒子类型可视化,明天你可能想要另一种类型。让每个盒子对象都包含数据似乎非常严格,因为它只给你一个选择。我会尝试使用一个处理数据解析的类和另一个类或一组类,将逻辑与视图尽可能分开,这些类对数据一无所知,只会显示颜色框、饼图、3D 图表ETC...
I think the general idea would be to keep things as flexible as possible , today you want to use the box type visualization, tomorrow you may want another type . To have each box object containing data seems pretty rigid as it gives you only one option. I would try to keep the logic as separated from the view as possible with a class that handles the parsing of data and another class or set of classes that wouldn't know anything about data and would just display color boxes , pie charts , 3D graphs etc...
我首先创建一个 StudentBox 类,它保存每个学生的数据,并有一个名为 ChangeColor 的方法,该方法接受颜色并将 StudentBox 颜色更改为传入颜色的颜色。然后我会在 AS3 中创建一个数组或向量来保存您创建的所有学生。
之后,您将向过滤器按钮添加一个监听器,以检测它们何时被单击,并让它们调用执行以下操作的函数:
1) 循环遍历包含每个 StudentBox 的数组中的所有 StudentBox
2) 对于循环遍历的每个 StudentBox,根据其过滤器更改 StudentBox 的颜色
I'd first create a class StudentBox which holds each students data and has a method called changeColor which accepts a color and changes the StudentBox color to that of the passed in color. Then I'd create an array or vector in AS3 which holds all the students you created.
After this you would add a listener to the filter buttons to detect when they are clicked and have them call a function which does the following:
1) Loop through all the StudentBoxes in the array holding each StudentBox
2) for every StudentBox you loop through, change the color of the StudentBox depending on its filter