25 Replies Latest reply on Jul 31, 2008 6:40 AM by Newsgroup_User

    Dynamically Create Repeater Element in ActionScript

    katychapman85
      Hi,

      I'm trying to dynamically create a repeater control with an image and a label control. I can do it directly in the MXML file but when I try and covert it into ActionScript it's not working. Can anyone see what the problem is with my code?

      public function GetPalettes():void{
      removeChild(document.FrontPage);
      Palettes.method = "GET";
      params = {"method": "GetPalettes", "BodyPartNo": document.PalettesMenu.selectedItem.@partNo};
      Palettes.cancel();
      Palettes.send(params);

      var VerticalBox:VBox = new VBox();
      VerticalBox.x = 10;
      VerticalBox.y = 10;
      VerticalBox.id = "VerticalBox";

      var PaletteRepeater:Repeater = new Repeater();
      PaletteRepeater.dataProvider = "{Palettes.lastResult.Palette}";
      PaletteRepeater.startingIndex = 0;
      PaletteRepeater.id = "PaletteRepeater";

      var PaletteImage:Image = new Image();
      PaletteImage.setStyle("HorizontalAlign", "left");
      PaletteImage.source = " http://localhost/Flex/Personalised%20Palettes-debug/{PaletteRepeater.currentItem.@PictureS rc}Med.png";
      PaletteImage.useHandCursor = true;
      PaletteImage.buttonMode = true;
      PaletteImage.mouseChildren = false;
      PaletteImage.id = "PaletteImage";

      var PaletteDescription:Label = new Label();
      PaletteDescription.text = "{PaletteRepeater.currentItem.@Description}";
      PaletteDescription.id = "PaletteDescription";

      document.MainPage.addChild(VerticalBox);
      VerticalBox.addChild(PaletteRepeater);
      PaletteRepeater.addChild(PaletteImage);
      PaletteRepeater.addChild(PaletteDescription);

      }

      Thanks
        • 1. Re: Dynamically Create Repeater Element in ActionScript
          Level 7

          "katychapman85" <webforumsuser@macromedia.com> wrote in message
          news:g6lgt8$1eh$1@forums.macromedia.com...
          > Hi,
          >
          > I'm trying to dynamically create a repeater control with an image and a
          > label
          > control. I can do it directly in the MXML file but when I try and covert
          > it
          > into ActionScript it's not working. Can anyone see what the problem is
          > with my
          > code?
          >
          > public function GetPalettes():void{
          > removeChild(document.FrontPage);
          > Palettes.method = "GET";
          > params = {"method": "GetPalettes", "BodyPartNo":
          > document.PalettesMenu.selectedItem.@partNo};
          > Palettes.cancel();
          > Palettes.send(params);
          >
          > var VerticalBox:VBox = new VBox();
          > VerticalBox.x = 10;
          > VerticalBox.y = 10;
          > VerticalBox.id = "VerticalBox";
          >
          > var PaletteRepeater:Repeater = new Repeater();
          > PaletteRepeater.dataProvider = "{Palettes.lastResult.Palette}";
          > PaletteRepeater.startingIndex = 0;
          > PaletteRepeater.id = "PaletteRepeater";
          >
          > var PaletteImage:Image = new Image();
          > PaletteImage.setStyle("HorizontalAlign", "left");
          > PaletteImage.source =
          > " http://localhost/Flex/Personalised%20Palettes-debug/{PaletteRepeater.currentIte
          > m.@PictureSrc}Med.png";
          > PaletteImage.useHandCursor = true;
          > PaletteImage.buttonMode = true;
          > PaletteImage.mouseChildren = false;
          > PaletteImage.id = "PaletteImage";
          >
          > var PaletteDescription:Label = new Label();
          > PaletteDescription.text = "{PaletteRepeater.currentItem.@Description}";
          > PaletteDescription.id = "PaletteDescription";
          >
          > document.MainPage.addChild(VerticalBox);
          > VerticalBox.addChild(PaletteRepeater);
          > PaletteRepeater.addChild(PaletteImage);
          > PaletteRepeater.addChild(PaletteDescription);
          >
          > }

          If you're using a repeater, let it do the repeating for you. You can't add
          one component to the displaylist multiple times and see multiple components.
          You still only have one component. Repeater doesn't seem to have anything
          like an itemRenderer property, which implies that you can only tell it
          "what" to repeat in MXML. If you could tell it "what" to repeat, it would
          have to be a ClassFactory, which means that it would have to already
          encapsulate the functionality you need (you can't make a VBox ClassFactory
          and then add an Image to it after the fact).

          Additionally, repeaters are typically used within containers that will do
          the layout for you.

          HTH;

          Amy


          • 2. Re: Dynamically Create Repeater Element in ActionScript
            katychapman85 Level 1
            Thanks Amy. Originally I had used a list control with ItemRenderer and Component elements with the Image and Label tag nested inside them. Again I could get it to work in MXML but not dynamically in ActionScript. The List element does have an ItemRenderer property but I'm not entirely sure how to use this in ActionScript.

            Basically I've got some images and some descriptions in a database which I'm retrieving in XML. I then want to have a list of the Images with the Description underneath. Would you be able to give me an example of how I can do this using ActionScript?

            Thanks for the help I'm very new to Flex, so I'm not entirely sure how to use all the different components yet.
            Katy
            • 3. Re: Dynamically Create Repeater Element in ActionScript
              ntsiii Level 3
              Are you dead-set against instantiating Repeater using mxml? It is so much simpler than what you are trying to do.

              Create a custom component the encapsulates everything that the repeated item needs to do. Pass in the entire currentItem in a public property. Bind to that property. Away you go.

              Tracy
              • 5. Re: Dynamically Create Repeater Element in ActionScript
                katychapman85 Level 1
                ntsiii - So would you just use Repeater in MXML and make it invisible until needed?

                "Create a custom component the encapsulates everything that the repeated item needs to do. Pass in the entire currentItem in a public property. Bind to that property. Away you go."

                Could you explain this a bit more?

                And yes you can use braces in ActionScript, that part works.
                • 7. Re: Dynamically Create Repeater Element in ActionScript
                  Level 7

                  "katychapman85" <webforumsuser@macromedia.com> wrote in message
                  news:g6lklo$54d$1@forums.macromedia.com...
                  > Thanks Amy. Originally I had used a list control with ItemRenderer and
                  > Component elements with the Image and Label tag nested inside them. Again
                  > I
                  > could get it to work in MXML but not dynamically in ActionScript. The List
                  > element does have an ItemRenderer property but I'm not entirely sure how
                  > to use
                  > this in ActionScript.
                  >
                  > Basically I've got some images and some descriptions in a database which
                  > I'm
                  > retrieving in XML. I then want to have a list of the Images with the
                  > Description underneath. Would you be able to give me an example of how I
                  > can do
                  > this using ActionScript?
                  >
                  > Thanks for the help I'm very new to Flex, so I'm not entirely sure how to
                  > use
                  > all the different components yet.

                  This example might help point you in the right direction:

                  http://examples.adobe.com/flex2/inproduct/sdk/photoviewer/PhotoViewer.html


                  • 8. Re: Dynamically Create Repeater Element in ActionScript
                    Level 7

                    "katychapman85" <webforumsuser@macromedia.com> wrote in message
                    news:g6mira$6d0$1@forums.macromedia.com...
                    > ntsiii - So would you just use Repeater in MXML and make it invisible
                    > until
                    > needed?

                    The repeater has no physical presence. So, until you set its dataProvider,
                    you won't see anything.

                    HTH;

                    Amy


                    • 9. Re: Dynamically Create Repeater Element in ActionScript
                      katychapman85 Level 1
                      Sorry that was my fault I didn't mean the Repeater control I meant the List control. What I've done at the moment is this:
                      <mx:List id="PalettePictures"
                      dataProvider="{Palettes.lastResult.Palette}"
                      x="331" y="103"
                      width="614" height="477"
                      change="GetPalette();"
                      backgroundColor="#FFFFFF"
                      themeColor="#FFFFFF"
                      visible="false">

                      <mx:itemRenderer>
                      <mx:Component>
                      <mx:VBox x="10" y="10" height="152">
                      <mx:Image
                      id="PaletteImage"
                      horizontalAlign="left"
                      source=" http://localhost/Flex/Personalised%20Palettes-debug/{data.@PictureSrc}Med.png"
                      useHandCursor="true"
                      buttonMode="true"
                      mouseChildren="false"/>
                      <mx:Label text="{data.@Description}"/>
                      </mx:VBox>
                      </mx:Component>
                      </mx:itemRenderer>
                      </mx:List>

                      Then when I require the PalettePictures I make it visible. The main reason I wanted to know how to do it in ActionScript is because I assumed it was more elegant to create the components dynamically rather than them be on the canvas but not visible.

                      This is the AJAX site I made: http://homepages.shu.ac.uk/~kchapma5/MakeItUp/MakeItUp.php
                      Basically I'm now trying to achieve the same thing using Flex.

                      One problem I am still having though is when someone click on a Palette type the list of Palettes are retrieved and made visible. However, if I click on a Palette to view it and then go back to the Palettes menu to view a different list of Palettes the previous Palettes flash up before the selected ones are loaded. If that makes sense.

                      So for example, if I choose to view the Eye Palettes and then select one of the Palettes, if I then decide to view the Lip Palettes the Eye Palettes will flash up quickly before the Lip ones are loaded. Any suggestions?

                      Thanks
                      • 10. Re: Dynamically Create Repeater Element in ActionScript
                        Level 7

                        "katychapman85" <webforumsuser@macromedia.com> wrote in message
                        news:g6n8so$sb0$1@forums.macromedia.com...
                        > Sorry that was my fault I didn't mean the Repeater control I meant the
                        > List
                        > control. What I've done at the moment is this:
                        > <mx:List id="PalettePictures"
                        > dataProvider="{Palettes.lastResult.Palette}"
                        > x="331" y="103"
                        > width="614" height="477"
                        > change="GetPalette();"
                        > backgroundColor="#FFFFFF"
                        > themeColor="#FFFFFF"
                        > visible="false">
                        >
                        > <mx:itemRenderer>
                        > <mx:Component>
                        > <mx:VBox x="10" y="10" height="152">
                        > <mx:Image
                        > id="PaletteImage"
                        > horizontalAlign="left"
                        >
                        > source=" http://localhost/Flex/Personalised%20Palettes-debug/{data.@Picture
                        > Src}Med.png"
                        > useHandCursor="true"
                        > buttonMode="true"
                        > mouseChildren="false"/>
                        > <mx:Label text="{data.@Description}"/>
                        > </mx:VBox>
                        > </mx:Component>
                        > </mx:itemRenderer>
                        > </mx:List>
                        >
                        > Then when I require the PalettePictures I make it visible. The main reason
                        > I
                        > wanted to know how to do it in ActionScript is because I assumed it was
                        > more
                        > elegant to create the components dynamically rather than them be on the
                        > canvas
                        > but not visible.

                        I think that you might get a slightly quicker load by doing it dynamically,
                        then slightly slower response when you actually do the creation, but I think
                        that might be the only difference.

                        > This is the AJAX site I made:
                        > http://homepages.shu.ac.uk/~kchapma5/MakeItUp/MakeItUp.php
                        > Basically I'm now trying to achieve the same thing using Flex.
                        >
                        > One problem I am still having though is when someone click on a Palette
                        > type
                        > the list of Palettes are retrieved and made visible. However, if I click
                        > on a
                        > Palette to view it and then go back to the Palettes menu to view a
                        > different
                        > list of Palettes the previous Palettes flash up before the selected ones
                        > are
                        > loaded. If that makes sense.

                        I'm not sure what else you are doing, but you might want to try setting the
                        dataProvider _before_ you switch the view to show the Palette again.

                        HTH;

                        Amy


                        • 11. Re: Dynamically Create Repeater Element in ActionScript
                          katychapman85 Level 1
                          This is my ActionScript function to get the Palettes:

                          public function GetPalettes():void{
                          document.FrontPage.visible = false;
                          document.PaletteCanvas.visible = false;
                          Palettes.url = " http://localhost/Flex/Personalised%20Palettes-debug/Palettes.php?BodyPartNo="
                          Palettes.url += document.PalettesMenu.selectedItem.@partNo;
                          Palettes.send();
                          document.PalettePictures.visible = true;
                          }


                          So I do make the PalettePictures visble after I've retrieved the Palettes but it still flashes the previous ones. Does the HTTPService have any kind of onComplete parameter so I can make the Palettes visible once they've been fully retrieved?

                          Thanks for the help
                          • 12. Re: Dynamically Create Repeater Element in ActionScript
                            Level 7

                            "katychapman85" <webforumsuser@macromedia.com> wrote in message
                            news:g6ndvo$5b0$1@forums.macromedia.com...
                            > This is my ActionScript function to get the Palettes:
                            >
                            > public function GetPalettes():void{
                            > document.FrontPage.visible = false;
                            > document.PaletteCanvas.visible = false;
                            > Palettes.url =
                            > " http://localhost/Flex/Personalised%20Palettes-debug/Palettes.php?BodyPartNo="
                            > Palettes.url += document.PalettesMenu.selectedItem.@partNo;
                            > Palettes.send();
                            > document.PalettePictures.visible = true;
                            > }
                            >
                            >
                            > So I do make the PalettePictures visble after I've retrieved the Palettes
                            > but
                            > it still flashes the previous ones. Does the HTTPService have any kind of
                            > onComplete parameter so I can make the Palettes visible once they've been
                            > fully
                            > retrieved?

                            Try this:

                            public function GetPalettes():void{
                            Palettes.url =
                            " http://localhost/Flex/Personalised%20Palettes-debug/Palettes.php?BodyPartNo="
                            Palettes.url += document.PalettesMenu.selectedItem.@partNo;
                            Palettes.send();
                            Palettes.addEventListener('result', onPaletteResult);
                            }

                            private function onPaletteResult(e:ResultEvent){
                            //ugh! broken encapsulation, but I don't know
                            //enough about your structure to fix it
                            document.FrontPage.visible=false;
                            document.PaletteCanvas.visible=false;
                            document.PalettePictures.visible=true;
                            }

                            HTH;

                            Amy


                            • 14. Re: Dynamically Create Repeater Element in ActionScript
                              Level 7

                              "katychapman85" <webforumsuser@macromedia.com> wrote in message
                              news:g6nika$a8e$1@forums.macromedia.com...
                              > That works :-) Thanks Amy!

                              You're welcome :-)


                              • 15. Re: Dynamically Create Repeater Element in ActionScript
                                katychapman85 Level 1
                                Hi Amy,

                                I was wondering if you could help me out with one other problem I'm having. I have an accordion menu, with 2 sections, 1 for choosing the palette and the 2nd for choosing the colours. When the application loads the Palette Menu is open. Once a Palette has been chosen I set a variable called PaletteType to either "Eyes", "Lips" or "Cheeks" depending on what palette has been chosen, I then toggle the Accordion Menu so that the Colours Menu is now showing. The contents of the Colours menu will depend on what the PaletteType variable is set as. However the first time the application is run and a Palette is selected the Colours menu is empty, if I then select another Palette the contents of the Colours menu adjusts accordingly. Do you know why the contents are not updating the first time a Palette is selected?

                                I hope I've given you enough information for that to make sense.

                                Thanks
                                Katy
                                • 16. Re: Dynamically Create Repeater Element in ActionScript
                                  katychapman85 Level 1
                                  These are the two functions I'm using in ActionScript:

                                  public function GetPalette(Picture:String, Description:String, Price:Number):void{
                                  GetPaletteMenu();
                                  var ImageSrc:String;
                                  ImageSrc = " http://localhost/Flex/Personalised%20Palettes-debug/";
                                  ImageSrc += Picture;
                                  ImageSrc += ".png";
                                  document.PaletteDescription.text = Description + " - £" + Price;
                                  document.Palette.source = ImageSrc;

                                  document.OtherPalettes.url = " http://localhost/Flex/Personalised%20Palettes-debug/OtherPalettes.php?BodyPartNo=";
                                  document.OtherPalettes.url += BodyPartNo;
                                  document.OtherPalettes.url += "&Palette="
                                  document.OtherPalettes.url += Picture;
                                  document.OtherPalettes.send();

                                  document.PalettePictures.visible = false;
                                  document.PaletteCanvas.visible = true;

                                  ToggleMenu(1);

                                  if (document.PalettePictures.selectedItem.@BodyPart == 1)
                                  {
                                  PaletteType = "Eyes";
                                  }
                                  else if (document.PalettePictures.selectedItem.@BodyPart == 2)
                                  {
                                  PaletteType = "Lips";
                                  }else{
                                  PaletteType = "Cheeks";
                                  }

                                  GetColoursMenu();
                                  }

                                  public function GetColoursMenu():void{
                                  if (PaletteType == "Eyes")
                                  {
                                  document.RadioButton1.label = "By Colour Family";
                                  document.RadioButton2.label = "By Eye Colour";
                                  }
                                  if (PaletteType == "Lips")
                                  {
                                  document.RadioButton1.label = "By Colour Family";
                                  document.RadioButton2.label = "By Skin Tone";
                                  }
                                  if (PaletteType == "Cheeks")
                                  {
                                  document.RadioButton1.label = "By Colour Family";
                                  document.RadioButton2.label = "By Skin Tone";
                                  }
                                  document.RadioButton1.selected = true;
                                  }
                                  • 17. Re: Dynamically Create Repeater Element in ActionScript
                                    Level 7

                                    "katychapman85" <webforumsuser@macromedia.com> wrote in message
                                    news:g6ptv1$sre$1@forums.macromedia.com...
                                    > These are the two functions I'm using in ActionScript:
                                    >
                                    > public function GetPalette(Picture:String, Description:String,
                                    > Price:Number):void{
                                    > GetPaletteMenu();
                                    > var ImageSrc:String;
                                    > ImageSrc = " http://localhost/Flex/Personalised%20Palettes-debug/";
                                    > ImageSrc += Picture;
                                    > ImageSrc += ".png";
                                    > document.PaletteDescription.text = Description + " - ?" + Price;
                                    > document.Palette.source = ImageSrc;
                                    >
                                    > document.OtherPalettes.url =
                                    > " http://localhost/Flex/Personalised%20Palettes-debug/OtherPalettes.php?BodyPartN
                                    > o=";
                                    > document.OtherPalettes.url += BodyPartNo;
                                    > document.OtherPalettes.url += "&Palette="
                                    > document.OtherPalettes.url += Picture;
                                    > document.OtherPalettes.send();
                                    >
                                    > document.PalettePictures.visible = false;
                                    > document.PaletteCanvas.visible = true;
                                    >
                                    > ToggleMenu(1);
                                    >
                                    > if (document.PalettePictures.selectedItem.@BodyPart == 1)
                                    > {
                                    > PaletteType = "Eyes";
                                    > }
                                    > else if (document.PalettePictures.selectedItem.@BodyPart == 2)
                                    > {
                                    > PaletteType = "Lips";
                                    > }else{
                                    > PaletteType = "Cheeks";
                                    > }
                                    >
                                    > GetColoursMenu();
                                    > }
                                    >
                                    > public function GetColoursMenu():void{
                                    > if (PaletteType == "Eyes")
                                    > {
                                    > document.RadioButton1.label = "By Colour Family";
                                    > document.RadioButton2.label = "By Eye Colour";
                                    > }
                                    > if (PaletteType == "Lips")
                                    > {
                                    > document.RadioButton1.label = "By Colour Family";
                                    > document.RadioButton2.label = "By Skin Tone";
                                    > }
                                    > if (PaletteType == "Cheeks")
                                    > {
                                    > document.RadioButton1.label = "By Colour Family";
                                    > document.RadioButton2.label = "By Skin Tone";
                                    > }
                                    > document.RadioButton1.selected = true;
                                    > }

                                    You need to wait for the result event to come back before you try to set
                                    anything based on it. I don't see where you're actually setting the Colours
                                    above, but it's probably before anything has come back from the server. Add
                                    an event listener to document.OtherPalettes to listen for the result event,
                                    then do whatever needs to be done there.

                                    HTH;

                                    Amy


                                    • 18. Re: Dynamically Create Repeater Element in ActionScript
                                      katychapman85 Level 1
                                      What I'm trying to do isn't based on what comes back from OtherPalettes. All I want to do is change the contents of the Colour menu depending on what Palette is selected. The problem seems to be with the accordion Menu, as if I start the application with the Accordion Menu open the Radio buttons adjust accordingly, but if the Colour Menu hasn't been opened it's not working.

                                      So when I first select a palette the Color Menu isn't updated but then if I select another Palette once the Colour Menu has been opened it works. It's almost as if it can't access the controls inside the Colour Menu in the Accordion before it's been opened once.
                                      • 19. Re: Dynamically Create Repeater Element in ActionScript
                                        katychapman85 Level 1
                                        Also I put a label outside of the accordion to display the PaletteType variable. And that changes to eyes, lips or cheeks when a palette is selected so this is the function that isn't working the very first time a palette is selected when the Colour Menu of the Accordion is closed:

                                        > public function GetColoursMenu():void{
                                        > if (PaletteType == "Eyes")
                                        > {
                                        > document.RadioButton1.label = "By Colour Family";
                                        > document.RadioButton2.label = "By Eye Colour";
                                        > }
                                        > if (PaletteType == "Lips")
                                        > {
                                        > document.RadioButton1.label = "By Colour Family";
                                        > document.RadioButton2.label = "By Skin Tone";
                                        > }
                                        > if (PaletteType == "Cheeks")
                                        > {
                                        > document.RadioButton1.label = "By Colour Family";
                                        > document.RadioButton2.label = "By Skin Tone";
                                        > }
                                        > document.RadioButton1.selected = true;
                                        > }

                                        But the Radio buttons will change the next time I click a palette. So I can't quite figure out what's wrong. As it should still update even if the Colour Menu is closed as the code is still there. And the PaletteType variabel is set.

                                        • 20. Re: Dynamically Create Repeater Element in ActionScript
                                          Level 7

                                          "katychapman85" <webforumsuser@macromedia.com> wrote in message
                                          news:g6qg6f$jno$1@forums.macromedia.com...
                                          > Also I put a label outside of the accordion to display the PaletteType
                                          > variable. And that changes to eyes, lips or cheeks when a palette is
                                          > selected
                                          > so this is the function that isn't working the very first time a palette
                                          > is
                                          > selected when the Colour Menu of the Accordion is closed:
                                          >
                                          > > public function GetColoursMenu():void{
                                          > > if (PaletteType == "Eyes")
                                          > > {
                                          > > document.RadioButton1.label = "By Colour Family";
                                          > > document.RadioButton2.label = "By Eye Colour";
                                          > > }
                                          > > if (PaletteType == "Lips")
                                          > > {
                                          > > document.RadioButton1.label = "By Colour Family";
                                          > > document.RadioButton2.label = "By Skin Tone";
                                          > > }
                                          > > if (PaletteType == "Cheeks")
                                          > > {
                                          > > document.RadioButton1.label = "By Colour Family";
                                          > > document.RadioButton2.label = "By Skin Tone";
                                          > > }
                                          > > document.RadioButton1.selected = true;
                                          > > }
                                          >
                                          > But the Radio buttons will change the next time I click a palette. So I
                                          > can't
                                          > quite figure out what's wrong. As it should still update even if the
                                          > Colour
                                          > Menu is closed as the code is still there. And the PaletteType variabel is
                                          > set.

                                          OK, let me see if I can get this straight...

                                          You have essentially this:

                                          Accordion
                                          -panel 1
                                          --stuff that calls GetPallette and GetColorsMenu()
                                          -panel 2
                                          --your RadioButtons

                                          If so, I'm surprised you're not getting runtime errors, since your
                                          creationPolicy is very likely to be the default, given the situation you've
                                          described.

                                          Try setting an event listener on the panel 2 show event, and calling
                                          GetColorsMenu() from there.

                                          HTH;

                                          Amy


                                          • 21. Re: Dynamically Create Repeater Element in ActionScript
                                            katychapman85 Level 1
                                            What I have is this:

                                            Accordion
                                            -panel 1
                                            --Links that call GetPallettes
                                            -panel 2
                                            --RadioButtons

                                            When the Get Palettes method is called all the palettes of that category are show in a canvas and when the user clicks on one of those palettes the GetPalettes and GetColoursMenu methods are called.

                                            "Try setting an event listener on the panel 2 show event, and calling GetColorsMenu() from there."

                                            This sounds like what I need to do, how do I reference Panel 2, would this be the name of the canvas in the Accordion menu. I tried this:
                                            document.Colours.addEventListener("show", GetColoursMenu);

                                            But that doesn't work, not sure if I'm doing that right. I think this is my problem with Flex at the moment. Where I'm so new at it I'm unaware what events and functions are available to me.

                                            I'm using IE to run it at the moment which hasn't got any debug tools on it to detect Flex runtime errors.
                                            • 22. Re: Dynamically Create Repeater Element in ActionScript
                                              katychapman85 Level 1
                                              Hey, Just to let you know I fixed the problem. I found this on a Blog:

                                              "This bug (SDK-11344) was brought up internally and investigated by my co-worker Kishan Venkataramana. The views in an Accordion don’t trigger the “show” event the first time they load. The workaround is to set creationPolicy=”all” on the Accordion. Now the “show” event will trigger the first time you load an Accordion view for all views except the first one. If you need some functionality triggered when the Accordion first loads with its first view, I would just call a function on the creationComplete handler as well as the show event."

                                              So I set the creationPolicy of the Accordion to all like it said and it fixed it

                                              Thanks for all your help Amy you're a star
                                              • 23. Re: Dynamically Create Repeater Element in ActionScript
                                                Level 7

                                                "katychapman85" <webforumsuser@macromedia.com> wrote in message
                                                news:g6qqbd$13k$1@forums.macromedia.com...
                                                > Hey, Just to let you know I fixed the problem. I found this on a Blog:
                                                >
                                                > "This bug (SDK-11344) was brought up internally and investigated by my
                                                > co-worker Kishan Venkataramana. The views in an Accordion don?t trigger
                                                > the
                                                > ?show? event the first time they load. The workaround is to set
                                                > creationPolicy=?all? on the Accordion. Now the ?show? event will trigger
                                                > the
                                                > first time you load an Accordion view for all views except the first one.
                                                > If
                                                > you need some functionality triggered when the Accordion first loads with
                                                > its
                                                > first view, I would just call a function on the creationComplete handler
                                                > as
                                                > well as the show event."
                                                >
                                                > So I set the creationPolicy of the Accordion to all like it said and it
                                                > fixed
                                                > it
                                                >
                                                > Thanks for all your help Amy you're a star

                                                You're welcome.

                                                -Amy


                                                • 24. Re: Dynamically Create Repeater Element in ActionScript
                                                  katychapman85 Level 1
                                                  Hey Amy,

                                                  I've put a thread up about this but thought I'd ask you as well as you've been a great help to me so far.

                                                  I have this function:
                                                  public function GetOptions(Menu:int):void{
                                                  document.MenuOptions.url = " http://localhost/Flex/Personalised%20Palettes-debug/MenuOptions.php?Menu=";
                                                  document.MenuOptions.url += Menu;
                                                  document.MenuOptions.send();
                                                  }

                                                  What I'm trying to do is when a user clicks on a Radio button this function is called and the number of the Menu required is sent to the function.

                                                  I've added this Event Listener to my Radio Button:

                                                  document.RadioButtons2.addEventListener(MouseEvent.CLICK, function():void{GetOptions(2);});

                                                  However, it's not working. Everything I've read suggests using an anonymous function in the Event Listener to pass the menu parameter but for some reason it's not working.
                                                  • 25. Re: Dynamically Create Repeater Element in ActionScript
                                                    Level 7

                                                    "katychapman85" <webforumsuser@macromedia.com> wrote in message
                                                    news:g6s89j$j6q$1@forums.macromedia.com...
                                                    > Hey Amy,
                                                    >
                                                    > I've put a thread up about this but thought I'd ask you as well as you've
                                                    > been
                                                    > a great help to me so far.
                                                    >
                                                    > I have this function:
                                                    > public function GetOptions(Menu:int):void{
                                                    > document.MenuOptions.url =
                                                    > " http://localhost/Flex/Personalised%20Palettes-debug/MenuOptions.php?Menu=";
                                                    > document.MenuOptions.url += Menu;
                                                    > document.MenuOptions.send();
                                                    > }
                                                    >
                                                    > What I'm trying to do is when a user clicks on a Radio button this
                                                    > function is
                                                    > called and the number of the Menu required is sent to the function.
                                                    >
                                                    > I've added this Event Listener to my Radio Button:
                                                    >
                                                    > document.RadioButtons2.addEventListener(MouseEvent.CLICK,
                                                    > function():void{GetOptions(2);});
                                                    >
                                                    > However, it's not working. Everything I've read suggests using an
                                                    > anonymous
                                                    > function in the Event Listener to pass the menu parameter but for some
                                                    > reason
                                                    > it's not working.

                                                    What version of Flex are you using? The Help for Flex 3 has this to say:

                                                    http://www.adobe.com/livedocs/flex/3/html/help.html?content=events_05.html

                                                    Defining event listeners inline
                                                    The simplest method of defining event handlers in Flex applications is to
                                                    point to a handler function in the component's MXML tag. To do this, you add
                                                    any of the component's events as a tag attribute followed by an ActionScript
                                                    statement or function call.

                                                    You add an event handler inline using the following syntax:

                                                    <mx:tag_name event_name="handler_function"/>

                                                    For example, to listen for a Button control's click event, you add a
                                                    statement in the <mx:Button> tag's click attribute. If you add a function,
                                                    you define that function in an ActionScript block. The following example
                                                    defines the submitForm() function as the handler for the Button control's
                                                    click event:

                                                    <mx:Script><![CDATA[
                                                    function submitForm():void {
                                                    // Do something.
                                                    }
                                                    ]]></mx:Script>
                                                    <mx:Button label="Submit" click="submitForm();"/>

                                                    Event handlers can include any valid ActionScript code, including code that
                                                    calls global functions or sets a component property to the return value. The
                                                    following example calls the trace() global function:

                                                    <mx:Button label="Get Ver" click="trace('The button was clicked');"/>

                                                    There is one special parameter that you can pass in an inline event handler
                                                    definition: the event parameter. If you add the event keyword as a
                                                    parameter, Flex passes the Event object and inside the handler function, you
                                                    can then access all the properties of the Event object.

                                                    The following example passes the Event object to the submitForm() handler
                                                    function and specifies it as type MouseEvent:

                                                    <?xml version="1.0"?>
                                                    <!-- events/MouseEventHandler.mxml -->
                                                    <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
                                                    <mx:Script><![CDATA[
                                                    import mx.controls.Alert;

                                                    private function myEventHandler(event:MouseEvent):void {
                                                    // Do something with the MouseEvent object.
                                                    Alert.show("An event of type '" + event.type + "' occurred.");
                                                    }
                                                    ]]></mx:Script>

                                                    <mx:Button id="b1" label="Click Me" click="myEventHandler(event)"/>

                                                    </mx:Application>
                                                    ...
                                                    It is best practice to include the event keyword when you define all inline
                                                    event listeners and to specify the most stringent Event object type in the
                                                    resulting listener function (for example, specify MouseEvent instead of
                                                    Event).

                                                    You can use the Event object to access a reference to the target object (the
                                                    object that dispatched the event), the type of event (for example, click),
                                                    or other relevant properties, such as the row number and value in a
                                                    list-based control. You can also use the Event object to access methods and
                                                    properties of the target component, or the component that dispatched the
                                                    event.

                                                    Although you will most often pass the entire Event object to an event
                                                    listener, you can just pass individual properties, as the following example
                                                    shows:

                                                    <?xml version="1.0"?>
                                                    <!-- events/PropertyHandler.mxml -->
                                                    <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
                                                    <mx:Script><![CDATA[
                                                    import mx.controls.Alert;

                                                    private function myEventHandler(s:String):void {
                                                    Alert.show("Current Target: " + s);
                                                    }
                                                    ]]></mx:Script>

                                                    <mx:Button id="b1" label="Click Me"
                                                    click="myEventHandler(event.currentTarget.id)"/>

                                                    </mx:Application>
                                                    ...
                                                    Registering an event listener inline provides less flexibility than using
                                                    the addEventListener() method to register event listeners. The drawbacks are
                                                    that you cannot set the useCapture or priority properties on the Event
                                                    object and that you cannot remove the listener once you add it.



                                                    ----------------------------



                                                    don't see anything in there about anonymous functions...?