Extending an existing component

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default Extending an existing component

    Hi...I'm trying to create a custom and I'm having problems adding child
    components to it, even though I think I"ve followed all the documentation I've
    read to create it. Here's my setup:

    - I extend TitleWindow in a class called MiniView. MiniView is defined in a
    class file called MiniView.as.

    - I attempt to add a ControlBar as a child component by overriding
    createChildren() in MiniView.as. I also add a call to super.createChildren().
    function createChildren(): Void {
    super.createChildren();

    - I create a child component via the recommended procedure
    var toolBar:ControlBar;
    toolBar = ControlBar(createClassObject(ControlBar, "toolBar1", 1,
    {width:"100%", backgroundColor:"#ff00ff", height:"25", marginTop:"0",
    marginBottom:"0", marginLeft:"0", horizontalAlign:"right"}));

    - At this point, I would expect my toolbar to be the only component visibile
    when I instantiate a MiniView object. That didn't work, but I continued on. Now
    I add two buttons to the toolbar
    toolBar.createChild(Button, "btnFreeze", 0, {label:"Freeze",
    backgroundColor:"#00ff00"});
    toolBar.createChild(Button, "btnResume", 0, {label:"Resume",
    backgroundColor:"#ff0000"});

    - Per some documentation I came across, I make a call to invalidate(). I also
    tried invalidateLayout(), but it had no effect either.
    //invalidateLayout();
    invalidate();

    - Debug to verifiy this method was called and made it to the end
    Alert.show("done creating children...");


    - In my main.mxml file, I add MiniView component to my application dynamically
    depending on a selection in a ComboBox.
    function doSomething(event): Void {
    var strTitle:String = event.target.selectedItem;
    views.createChild(MiniView, undefined, {title:strTitle, id:"view1",
    width:"100%", height:"290"})//, backgroundImage:strTitle + ".jpg"});
    }

    - While I do get the TitleWindow on the screen and the Alert box to display,
    none of my sub-components are visible. Am I missing something? I did come
    across a different procedure that tells how to use the compile tool to compile
    a class into a .swc file, but it's my impression that's completely optional.
    Since no one else posted regarding this, I'm assuming that I'm missing a vital
    step when it comes to overriding a component. Would appreciate the assistance...

    Thanks,

    Quest
    General Dynamics


    Any ideas???



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





    class vmoc.MiniView extends mx.containers.TitleWindow {
    import mx.containers.ControlBar;
    import mx.controls.Alert;
    import mx.controls.Button;
    import mx.controls.Label;

    /*
    The local value of _myName is private, while the getter and setter methods
    are public.
    In getters and setters, you cannot use the same name of the property in the
    function name.
    As a result, you should use some convention, such as prefixing the member
    name with an underscore character (_).
    */

    private var _myName:String = "abc";

    public function get myName():String {
    return _myName;
    }

    public function set myName(name:String) {
    _myName = name;
    }
    /*
    function MiniView() {
    super.TitleWindow();
    // var toolBar:ControlBar = ControlBar(createChild(ControlBar, "toolBar",
    {width:"100%", backgroundColor:"#ff00ff", height:"25", marginTop:"0",
    marginBottom:"0", marginLeft:"0", horizontalAlign:"left"}));
    }
    */
    function createChildren(): Void {
    super.createChildren();

    var toolBar:ControlBar;
    var buttonPress:Button;

    toolBar = ControlBar(createClassObject(ControlBar, "toolBar1", 1,
    {width:"100%", backgroundColor:"#ff00ff", height:"25", marginTop:"0",
    marginBottom:"0", marginLeft:"0", horizontalAlign:"right"}));
    toolBar.createChild(Button, "btnFreeze", 0, {label:"Freeze",
    backgroundColor:"#00ff00"});
    toolBar.createChild(Button, "btnResume", 0, {label:"Resume",
    backgroundColor:"#ff0000"});
    // invalidateLayout();
    invalidate();
    Alert.show("done creating children...");
    }
    }

    Mister Quest Guest

  2. Similar Questions and Discussions

    1. Is it possible to set an existing component as child ofa container?
      Hi, I have a container, a HBox named hbox. This container will have only one child. Every time I destory the previous child, then create a new...
    2. Extending CF PoP.
      Is there anyway to extend CFPoP to support additional encoding types? I am getting ' java.io.UnsupportedEncodingException: iso-3979-1. ' Could...
    3. How to make a protected property in the base component public in the derived component?
      I have a base component, from which several components derive. What I want is to just publish some of the protected properties in the base...
    4. Extending the Window Component in Flash MX 2004
      Hi All, I have looked for information on the Window component in Flash MX 2004 and the only examples I can find are examples of 3rd party...
    5. Problem with creating a Component and using existing functions
      Ok, I've got the MovieClip setup as a component, adding code to the #initclip pragma to declare the class and link it to the ID in the library...
  3. #2

    Default Re: Extending an existing component

    Your problem here may be that the third argument to your calls to
    createClassObject are both zero, they should be different values. The third
    argument is the z index of the child created, if they're both zero, you
    effectively replace the first child at index 0 with 2nd child.



    insguy Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139