8 Replies Latest reply on Mar 16, 2010 11:12 AM by dtangram

    ItemClickEvent

    dtangram

      I'm trying to display an image by clicking on a link on a LinkBar. I'm using this code in my Actionscript code in Flex:

       

      private function invoiceClick(event:itemClickEvent):void

      {

           event.label == "Invoicing"

           var image:URLRequest = new URLRequest("InvoiceHome.swf");

      }

       

       

      Then, in the LinkBar code, I use itemClick like this, itemClick="invoiceClick(event)". But when I click on the Invoicing link on the LinkBar nothing happens. Could someone, please, tell me what I'm doing wrong.

       

      Thank you.

        • 1. Re: ItemClickEvent
          AdrianWiecek Level 3

          Hi,

           

          URLRequest doesn't load the file from the url, it just defines a request. To Load image you can use Loader class or Image class.

           

          private function  invoiceClick(event:ItemClickEvent):void

          {

               //are you missing if statement?

               if(event.label == "Invoicing")

               {

                    img.source = "InvoiceHome.swf";

               }

          }

           

          <mx:Image id="img"/>

           

          Regards,

          Adrian

          1 person found this helpful
          • 2. Re: ItemClickEvent
            dtangram Level 1

            I used the image class, but only a blank screen displayed when I tested it. I used the Loader class, but the image still did not load. Here is the code I used. Thank you, I did forget to use the if statement.

             

            private function invoiceClick(event:ItemClickEvent):void

            {

                 if(event.label == "Invoicing");

                 {

                      var invoiceImage:URLRequest = new URLRequest("InvoiceHome.swf");

                      var invoiceLoader.Loader = new Loader();

                      invoiceLoader.load(invoiceImage);

                      addChild(invoiceLoader);

                 }

            }

             

            Any thoughts?

            • 3. Re: ItemClickEvent
              dtangram Level 1

              Here is more of my code.

               

              <mx:LinkBar

               

               

              id="linkBar" color="#ffffff" x="158.2" y="93.1" width="664" dataProvider="{myViewStack}" borderStyle="none" themeColor="#FFFFFF" fontSize="10"

              height="

              23.95" borderThickness="0" alpha="1.0" disabledColor="#bebebe" itemClick="ntaClick(event), invoiceClick(event)" />

               

               

               

              <mx:ViewStack id="myViewStack" borderStyle="none" width="607.15686" height="30" x="146.8" y="110.7" >

               

              <mx:VBox

               

              id="invoicing" x="360.5" y="89.1" label="Invoicing" color="#FFFFFF" fontSize="8" themeColor="#FFFFFF"

              cornerRadius="

              0" fontWeight="normal" width="512.63336" height="24.600002" >

               

              <mx:HBox width="505.3333" paddingTop="3" height="23">

               

              <mx:LinkButton id="newin" label="New Invoice" color="#000000" themeColor="#FFFFFF" fontSize="9" click="showTrans(),selectionClick2(event);" fontWeight="normal" width="92.33333" height="20" cornerRadius="0"/>

               

              <mx:LinkButton id="pend" label="Pending" color="#000000" themeColor="#FFFFFF" cornerRadius="0" fontSize="9" click="myViewStack2.selectedChild=pendingSales,selectionClick2(event);" fontWeight="normal" width="66.66667" height="20"/>

               

              <mx:LinkButton id="fcs" label="Fax Cover Sheet" color="#000000" themeColor="#FFFFFF" cornerRadius="0" fontSize="9" click="myViewStack2.selectedChild=faxCover,selectionClick2(event);" fontWeight="normal" width="115" height="20"/>

               

              <mx:LinkButton id="pod" label="PODs Due" color="#000000" themeColor="#FFFFFF" cornerRadius="0" fontSize="9" click="myViewStack2.selectedChild=PODs,selectionClick2(event);" fontWeight="normal" width="78" height="20"/>

               

              <mx:LinkButton id="inImport" label="Invoice Import" color="#000000" themeColor="#FFFFFF" fontSize="9" click="showInvImport(),selectionClick2(event);" cornerRadius="0" fontWeight="normal" width="112.33333" height="20"/>

               

              </mx:HBox>

               

              </mx:VBox>

               

              </mx:ViewStack>

               

               

               

              • 4. Re: ItemClickEvent
                Sebastien V. Level 3

                There's a semicolon (;) after your if statement. Remove it.

                1 person found this helpful
                • 5. Re: ItemClickEvent
                  dtangram Level 1

                  Thank you. I, also, place a period before Loader and I should have added a colon. Here are the corrections.

                   

                  private function invoiceClick(event:ItemClickEvent):void

                  {

                       if(event.label == "Invoicing")

                       {

                            var invoiceImage:URLRequest = new URLRequest("InvoiceHome.swf");

                            var invoiceLoader:Loader = new Loader();

                            invoiceLoader.load(invoiceImage);

                            addChild(invoiceLoader);

                       }

                  }

                   

                  However, after making these changes, my image still doesn't load.

                  • 6. Re: ItemClickEvent
                    AdrianWiecek Level 3

                    Is InvoiceHome.swf in the same folder as class you're loading it from?

                    If it's in for example in assets folder, request should be:

                     

                    var invoiceImage:URLRequest = new URLRequest("assets/InvoiceHome.swf");

                     

                    You should also add event listeners to loader.contentLoaderInfo for Event.COMPLETE to see if loader finished loading with success.

                    • 7. Re: ItemClickEvent
                      Sebastien V. Level 3

                      Also, check that the swf-loading code is called (by adding an Alert.show( "woohoo") in the if statement for instance).

                      • 8. Re: ItemClickEvent
                        dtangram Level 1

                        Success!!! I found the answer. Here is the code.

                         

                        <mx:Script>
                             <![CDATA[
                                    import mx.events.ItemClickEvent;


                                    private function invoiceClick(event:ItemClickEvent):void
                                      {
                                            if (event.label == "Invoicing")
                                              {
                                                     myViewStack2.selectedChild=inHomeNew;
                                               }
                                      }

                              ]]>
                        </mx:Script>


                        <mx:LinkBar id="linkBar" color="#ffffff" x="158.2" y="93.1" width="664" dataProvider="{myViewStack}" borderStyle="none"

                                  themeColor="#FFFFFF" fontSize="10" height="23.95" borderThickness="0" alpha="1.0" disabledColor="#bebebe" itemClick="ntaClick(event),

                                  invoiceClick(event), accountsClick(event)" />
                         
                        <mx:ViewStack id="myViewStack" borderStyle="none" width="607.15686" height="30" x="146.8" y="110.7" >

                             <mx:VBox id="invoicing" x="360.5" y="89.1" label="Invoicing" color="#FFFFFF" fontSize="8" themeColor="#FFFFFF"
                                  cornerRadius="0" fontWeight="normal" width="512.63336" height="24.600002" >

                                  <mx:HBox width="505.3333" paddingTop="3" height="23">
                                          <mx:LinkButton id="newin" label="New Invoice"  color="#000000" themeColor="#FFFFFF" fontSize="9"

                                                 click="showTrans(),selectionClick2(event);" fontWeight="normal"  width="92.33333" height="20" cornerRadius="0"/>
                                          <mx:LinkButton id="pend" label="Pending"  color="#000000" themeColor="#FFFFFF" cornerRadius="0" fontSize="9"

                                                 click="myViewStack2.selectedChild=pendingSales,selectionClick2(event);" fontWeight="normal" width="66.66667" height="20"/>

                                          <mx:LinkButton id="fcs" label="Fax Cover Sheet"  color="#000000" themeColor="#FFFFFF" cornerRadius="0" fontSize="9"

                                                 click="myViewStack2.selectedChild=faxCover,selectionClick2(event);" fontWeight="normal" width="115" height="20"/>              
                                          <mx:LinkButton id="pod" label="PODs Due"  color="#000000" themeColor="#FFFFFF" cornerRadius="0" fontSize="9"

                                                 click="myViewStack2.selectedChild=PODs,selectionClick2(event);" fontWeight="normal" width="78" height="20"/>
                                         <mx:LinkButton id="inImport" label="Invoice Import"  color="#000000" themeColor="#FFFFFF" fontSize="9"

                                                 click="showInvImport(),selectionClick2(event);" cornerRadius="0" fontWeight="normal" width="112.33333" height="20"/>
                                  </mx:HBox>
                             </mx:VBox>
                        </mx:ViewStack>

                        <mx:ViewStack id="myViewStack2" backgroundColor="0xffffff" borderThickness="2" borderColor="#444444" borderStyle="solid"

                                  x="152" y="143.3" width="962" height="600">

                                       <mx:Canvas id="inHomeNew" width="962" height="600">

                                                 <mx:SWFLoader source="InvoiceHome.swf" x="0" y="0" width="958" height="595"/>
                                       </mx:Canvas>
                        </mx:ViewStack>

                         

                        Thank you AdrianWiecek & NoNick4Me for your replies. I greatly appreciate it.