0 Replies Latest reply on Jun 3, 2009 1:02 PM by rcanulla

    Display objects in class keep getting set to display=false... Please help!

    rcanulla Level 1

      Hi there,

       

      I have an app that displays XML as items. I am taking the createLayout() and trying to create a class that i can call from my custom component rather than having tons of code in the same file. The issue i am having is that when i call it, and run/debug, the display objects (text,links,date..) all have their visible property set to false. This happens even though I set the property to true in my code. Please help!

       

      package com.ryancanulla.utils
      {
           import flash.display.Sprite;
           import flash.events.MouseEvent;
           import flash.net.URLRequest;
           import flash.net.navigateToURL;
           import flash.text.TextFormat;
          
           import mx.collections.XMLListCollection;
           import mx.containers.Canvas;
           import mx.containers.HBox;
           import mx.containers.VBox;
           import mx.controls.CheckBox;
           import mx.controls.ComboBox;
           import mx.controls.LinkButton;
           import mx.controls.Text;
          
           public class CreateLayout extends Sprite {
               
           //--------------------------------------------------
           //
           //     Display Vars
           //
           // --------------------------------------------------
                private var vBox:VBox;
                private var hBox:HBox;
                private var titleText:LinkButton;
                private var itemInfo:Text;
                private var abstract:Text;
                private var archive:CheckBox;
                private var rateItem:ComboBox;
                private var category:ComboBox;
                private var container:VBox;
                private var clickURL:Text;
                private var canvas:Canvas;
                private var titleFormat:TextFormat;
               
                public function CreateLayout(listCollection:XMLListCollection)
                {
                     listCollection = listCollection;
                    
                     container = new VBox();
                     var categoryLabels:Array = new Array("Health","Industrial","Emerging Tech","Food & Ag");
                     var rateLabels:Array = new Array("Positive","Neutral","Negative");

                     for(var i:int=0; i<listCollection.length; i++) {
                          canvas = new Canvas();
                          hBox = new HBox();
                          titleText = new LinkButton();
                          titleFormat = new TextFormat();
                          itemInfo = new Text();
                          abstract = new Text();
                          archive = new CheckBox();
                          rateItem = new ComboBox();
                          category = new ComboBox();
                          clickURL = new Text();
                         
                          titleText.label = listCollection.getItemAt(i).title;
                          titleText.addEventListener(MouseEvent.CLICK, getURL);
                          titleText.width = 400;
                         
                          clickURL.text = listCollection.getItemAt(i).clickurl;
                          clickURL.visible = false;
                          clickURL.includeInLayout = false;
                         
                          itemInfo.text = listCollection.getItemAt(i).source + " | " + listCollection.getItemAt(i).date;
                          itemInfo.y = 25;
                          abstract.text = listCollection.getItemAt(i).abstract;
                          abstract.y = 42;
                          abstract.visible = true;
                          abstract.includeInLayout = true;
                         
                          abstract.width = 400;
                          abstract.height= 60;;
                          archive.label = "Archive";
                         
                          category.prompt = "Category";
                          category.dataProvider = categoryLabels;
                          category.rowCount = categoryLabels.length;
                          category.visible = false;
                          category.includeInLayout = false;
                          category.width = 95;
                          category.height = 20;

                          rateItem.prompt = "Rate";
                          rateItem.dataProvider = rateLabels;
                          rateItem.visible = false;
                          rateItem.includeInLayout = false;
                          rateItem.width = 95;
                          rateItem.height = 20;
                         
                          canvas.addChild(titleText);
                          canvas.addChild(clickURL);
                          canvas.addChild(itemInfo);
                          canvas.addChild(abstract);
                          canvas.addChild(hBox);
                         
                          hBox.addChild(archive);    
                          hBox.addChild(category);
                          hBox.addChild(rateItem);
                          hBox.y = abstract.y + 60;
                          hBox.percentWidth = 80;
                          hBox.percentHeight = 80;
                          //archive.addEventListener(Event.CHANGE, toggleArchive);    
                                        
                          container.addChild(canvas);         
                     }
                     container.x = 10;
                     container.y = 10;
                     container.visible = true;
                     addChild(container);

                }
                //-------------------------------------------------------------------------
              // Called when someone clicks on the titleLink. This function pulls the
              // origional website URL up in a seperate browser window
              //-------------------------------------------------------------------------
              private function getURL(e:MouseEvent):void {
                        var link:LinkButton = e.currentTarget as LinkButton;
                        var canvas:Canvas = link.parent as Canvas;
                        var clickURL:Text = canvas.getChildAt(1) as Text;
                        var url:URLRequest = new URLRequest(clickURL.text);
                        navigateToURL(url);
                       
                     trace(clickURL.text);
              }

           }
      }

       

       

      Where I instantiate the class. List collection is an XMLListCollection which contains XML data.

      private var createLayout:CreateLayout;
      createLayout = new CreateLayout(listCollection);