Strange behaviour of Tree component

I’m  making a tree like menu structure. It is already a hacky business but now I encountered another problem. And I have no clue where it is happening and if I do something wrong or Flex is messing it up.

I have a Tree component that uses a tree renderer to render the items. In this tree renderer I determine if it has children and style it by setting the left position and adding an icon.

If you open, close, open “test 2” in the example under this paragraph you see that the + sign icon is changing position. But the styling function (called init() in treeItemRenderer) that is setting that + icon is only called once. I get the idea that he is mirroring the items after the click. I have the source here. I hope some one else knows how to solve this.

Example
[SWF]http://arnomanders.nl/upload/testTree/treeTest.swf, 200, 400[/SWF]


Posted

in

, , , , ,

by

Comments

5 responses to “Strange behaviour of Tree component”

  1. Maikel Sibbald Avatar

    Source is enabled, but I’m getting a scary hamster 😉

    1. Arno Manders Avatar

      Damn those hamsters!

      I disabled the source and uploaded it to here. And I added some links in the post 😉 First time I use a plugin to add a swf inside a post.

  2. Maikel Sibbald Avatar

    I see what you are doing….. never use data in a creationComplete handler or what so ever.

    In treeItemRenderer.mxml move this part:

    if (data.isChild as Boolean){
    this.SecondCanvas.x = (data.depth + 1) * 15;
    this.mainLabel.setStyle(“left”, 5);
    this.mainImage.visible = false;
    }else{
    if (data.depth < 1){
    this.mainLabel.setStyle(“fontWeight”,”bold”);
    }
    this.SecondCanvas.x = (data.depth) * 25;
    if (data.children == null){
    this.mainImage.visible = false;
    //this.SecondCanvas.x =;
    //this.mainLabel.x = 0;
    }else{
    this.mainLabel.setStyle(“left”, 19);
    this.mainImage.visible = true;
    //this.SecondCanvas.x = (data.depth + 1) * 20;
    }
    }

    To:

    override public function set data

    Also you start that with a capital letter….. so it would be TreeItemRenderer….mxml will be translated to a actual class.

    1. Arno Manders Avatar

      Thank you that did the trick. I also found the solution by just calling that code also on Click and Change event But this is cleaner

  3. Maikel Sibbald Avatar

    As long as it is working for ya! 😉

Leave a Reply

Your email address will not be published. Required fields are marked *