0

i have a class (TheList.as). in which i have an array "Data" and it has a couple of values. Then i have a loop through which i am creating a scrollable list which uses the values from "Data" array. [I am trying make a unit converter]

Then i have another class "Units.as". In that class i have created three instances of "TheList". A main list ("myList"), and to sublists "ListFrom" and "ListTo". They are using values from "Data" array. Now i have text field whose value changes to whatever item is clicked. When i click "Angle" in the main list, i want the sublists to get populated with ("Degree", "Radian" etc)..

Here is what i tried

if(myList._TextLabel.text == "Angle")
{
ListFrom.Data = ["Degree", "Radian"];
}

But nothing happens, i do not get any error either. When i do this in an "ENTER_FRAME" event and trace (ListFrom.Data), i can see that the values change, but they do not get assigned to the list items in the list. I would really appreciate the help. Thanks!

Here are complete Classes for understanding the situation better(the code is pretty messy, as i am a newbie to OOP)

TheList.as: http://pastebin.com/FLy5QV9i Units.as : http://pastebin.com/z2CcHZzC

4

2 回答 2

0

在您调用 ListFrom.Data = ["Degree","Radian"] 的地方,确保当数据更改时,ListFrom 中的渲染已设置新数据。比如你可以在 ListFrom 中使用 MyRender 进行显示,你应该在 MyRender 中的 set data 方法中进行调试。您应该在调用 ListFrom.Data = ["Degree","Radian"]; 之后调用下面的代码

for (var i:int = 0; i < Data.legnth;i++) {
    var render:MyRender = ListFrom[i] as MyRender;

    if (render) {
         render.data = Data[i];
    } else {
         var render:MyRender = new MyRender();
         render.data = Data[i];
         ListFrom.addChild(render);
    }
}
于 2013-06-04T07:02:32.060 回答
0

您可以使用事件侦听器、单例类或将一个类引用到另一个类,具体取决于您想要的样式。所有这些都同样有效且快速/高效。

于 2013-06-04T07:13:43.877 回答