5 Replies Latest reply on Nov 20, 2008 11:24 AM by Newsgroup_User

    change UIComponent to extend a custome class?

    bmilesp
      hello,

      I was hoping to shed some light of extending core classes. I added some properties in FlexSprite.as, in a custom class called ModFlexSprite.as, and had the core UIComponent extend ModFlexSprite.as. However, these properties cannot be accessed vis the ItemListRenderer (which extends UIComponent->which extends FlexSprite).

      I realized that it's because of this code in the ListBase class:

      protected function moveRowVertically(i:int, numCols:int, moveBlockDistance:Number):void
      {
      var r:IListItemRenderer;

      for (var j:int = 0; j < numCols; j++)
      {
      r = listItems [j];
      r.move(r.x, r.y + moveBlockDistance);
      }
      rowInfo
      .y += moveBlockDistance;
      }

      i wanted to add properties to the var listItems via the new ModFlexSprite. so if i try to use my new ModFlexSprite properties, flex throws an error, saying 'undefined property'. Now, as you see, the var r casts as a IListItemRenderer, which is an interface, that never touches ModFlexSprite. Does this mean i have to create a custom Interface as well and implement it in the IListItemRenderer for my ModFlexSprite properties to work?

      thank you in advance! -brandon
        • 1. Re: change UIComponent to extend a custome class?
          atta707 Level 2
          Are you saying you changed the code in the Flex's built-in FlexSprite class? If so, that's hardly a coll idea :) Nevertheless, did you rebuilt (recompile) the entire Flex framework so that these changes are visible to ALL the child classes of FlexSprite and UIComponent?

          Maybe it would be helpful if described the problem you're trying to solve. There could be other ways to skin this cat!

          ATTA
          • 2. change UIComponent to extend a custome class?
            bmilesp Level 1
            i didn't change the code in the FlexSprite class. Rather I created a class called ModFlexSprite that extended the FlexSprite class, and in UIComponent.as i changed the class to extend ModFlexSprite instead of FlexSprite. How would I recompile the entire flex framework in flex 3?

            What I want to ultimately do is to create a list that has a tweened scrolling effect. I thought the first step would be to extend the List class and override the moveRowVertically method (from ListBase.as, see first post in thread) and change the line:

            r.move(r.x, r.y + moveBlockDistance);

            to:

            TweenMax.to(r,1,{y:r.y}); //using TweenMax Class

            This works as expected when you click the scroll arrow and wait for the tween to finish, then click the arrow again. But if you scroll the thumb or click the scroll arrow before the tween ends, then unexpected tween issues occur. You can see the example here. this is because the r.y value is being calculated in a number of places in the ListBase class- before the tween is finished, and moving the listItem(s) into unexpected y positions.

            So, to fix that issue, i wanted to extend FlexSprite so that in the get y method, it would check to see if an "end_y" property was set first, and return the end_y value instead of the y value:

            //in ModFlexSprite:
            override public function get y():Number{
            return = (end_y)? end_y : _y;
            }

            So then i could do something like this:

            r.end_y = r.y + moveBlockDistance;

            TweenMax.to(r,1,{y:r.y, onComplete:r.remove_end_y})

            the r.remove_end_y method would remove the end_y value when the tween completes. This should take care of the scrolling of items that are already on screen.

            I haven't figured out a way to animate the ListItems that are added to the list (as you can see in the example in the link above, the ones that "appear" if you click the scroll arrow). If you have any suggestions i would be greatful! Thank you. -b
            • 3. Re: change UIComponent to extend a custome class?
              Level 7

              "bmilesp" <webforumsuser@macromedia.com> wrote in message
              news:gg09gd$fst$1@forums.macromedia.com...
              > hello,
              >
              > I was hoping to shed some light of extending core classes. I added some
              > properties in FlexSprite.as, in a custom class called ModFlexSprite.as,
              > and had
              > the core UIComponent extend ModFlexSprite.as. However, these properties
              > cannot
              > be accessed vis the ItemListRenderer (which extends UIComponent->which
              > extends
              > FlexSprite).
              >
              > I realized that it's because of this code in the ListBase class:
              >
              > protected function moveRowVertically(i:int, numCols:int,
              > moveBlockDistance:Number):void
              > {
              > var r:IListItemRenderer;
              >
              > for (var j:int = 0; j < numCols; j++)
              > {
              > r = listItems [j];
              > r.move(r.x, r.y + moveBlockDistance);
              > }
              > rowInfo
              .y += moveBlockDistance;
              > }
              >
              > i wanted to add properties to the var listItems via the new ModFlexSprite.
              > so
              > if i try to use my new ModFlexSprite properties, flex throws an error,
              > saying
              > 'undefined property'. Now, as you see, the var r casts as a
              > IListItemRenderer,
              > which is an interface, that never touches ModFlexSprite. Does this mean i
              > have
              > to create a custom Interface as well and implement it in the
              > IListItemRenderer
              > for my ModFlexSprite properties to work?

              What you'll need to do is copy all of the FlexSprite code into a new as file
              in your project that is in a directory structure that's identical to the
              original Adobe package structure. Name it FlexSprite.as, and make your
              changes there. Now, your FlexSprite will be used for all Framework Classes
              when they compile. This technique is known as "monkey patching."

              However, why not just create a subclass of UIComponent to use as an
              itemRenderer and override the setter on the y value?


              • 4. Re: change UIComponent to extend a custome class?
                bmilesp Level 1
                yes, monkey patch, excellent! Thank you!

                I tried to monkey patch the FlexSprite component, and that worked, but i don't like keeping altered, patched copies of the framework code im my different projects.

                So you're saying that i should extend the UIComponent as a custom itemRenderer instead and override the y getter/setter there? That makes more sense because I would only have to then extend the list class and override there. No more mokeypatching!

                Thanks again -b
                • 5. Re: change UIComponent to extend a custome class?
                  Level 7

                  "bmilesp" <webforumsuser@macromedia.com> wrote in message
                  news:gg4cq6$3k5$1@forums.macromedia.com...
                  > yes, monkey patch, excellent! Thank you!
                  >
                  > I tried to monkey patch the FlexSprite component, and that worked, but i
                  > don't
                  > like keeping altered, patched copies of the framework code im my different
                  > projects.
                  >
                  > So you're saying that i should extend the UIComponent as a custom
                  > itemRenderer
                  > instead and override the y getter/setter there? That makes more sense
                  > because I
                  > would only have to then extend the list class and override there. No more
                  > mokeypatching!
                  >
                  > Thanks again -b

                  You're welcome ;-).

                  FWIW, if I get some extra time over Christmas, I have a date with the Flash
                  component kit to see if I can work out a better container class that
                  supports this.