19 Replies Latest reply on Apr 1, 2009 8:07 AM by Seglespaan

    anyone used rogue development object handles

    Seglespaan Level 1
      Hi,

      Has anyone got any experience of the above?

      I've place a text area inside an object handle which resizes and rotates as I want.

      However I want to target the selected Item,

      so say I have two instances of an object handle called oh1 and oh2, inside each is a text area. As i said these can be resized and rotated as desired but what i want to do now is use a color picker to change the text color of the selected object handle.

      I've tried using the built in selection manager but as yet can not get the desired result.

      if anyone has used this flex add on before and knows what I' talking about i can post the relevent code.

      Cheers

      Tim
        • 1. Re: anyone used rogue development object handles
          Peter Hahmann Level 1
          I'm not sure if I understood what you need. But if you post the code here, I could maybe help you.

          regards,
          Peter
          • 2. Re: anyone used rogue development object handles
            Seglespaan Level 1
            Ok here's my code

            [code]

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical" xmlns:oh="com.roguedevelopment.objecthandles.*" creationComplete="init()" xmlns:popupbar="com.roguedevelopment.popupbar.*" xmlns:sample="com.roguedevelopment.objecthandles.sample.*">
            <mx:Style source="../assets/FlashTypeStyles.css"/>

            <mx:Script>
            <![CDATA[
            import mx.controls.Image;
            import com.roguedevelopment.objecthandles.ObjectHandleEvent;
            import com.roguedevelopment.objecthandles.ObjectHandlesMouseCursors;
            import flash.events.Event;
            import mx.events.DropdownEvent;

            [Embed(source="resize_handle.png")]
            protected var resize_handle:Class;
            [Embed(source="rotate_handle.png")]
            protected var rotate_handle:Class;


            var childArray = new Array;

            private function changeEvt(event:Event):void {


            var currSelect:String = new String (SelectionManager.instance.currentlySelected);
            var selectedObject:String = currSelect.substring(44,47);


            SelectionManager.instance.currentlySelected(currentOH)



            var numChildren:Number = oh1.numChildren;
            for (var i:int = 0; i < numChildren; i++) {
            //trace(oh1.getChildAt(i));
            }

            var tits:Object = oh1.getChildAt(0) ;
            //trace(tits);
            }





            /*
            protected function init() : void
            {
            var oh:ObjectHandles = new ObjectHandles();
            oh.height = 50;
            oh.width = 50;
            oh.resizeHandleImage = resize_handle;

            var image:Image = new Image();
            image.source = "snowflake.png";
            oh.addChild(image);
            oh.allowRotate = true;
            image.percentHeight = 100;
            image.percentWidth = 100;
            image.maintainAspectRatio = true;

            genericExamples.addChild(oh);
            }
            */
            ]]>
            </mx:Script>

            <mx:Array id="fontsArray">
            <mx:String>Arial</mx:String>
            <mx:String>Verdana</mx:String>
            <mx:String>Georgia</mx:String>
            </mx:Array>






            <oh:ObjectHandles id="oh1" allowRotate="true" x="10" y="20" width="100" height="20" minHeight="1" minWidth="1" label="tits" >
            <mx:TextArea
            borderColor="#FFFFFF"
            height="{oh1.height}"
            width="{oh1.width}"
            resize="true"
            x="0" y="0"
            fontWeight="bold"
            fontSize="15"
            fontFamily="Verdana"
            color="{cp1.selectedColor}"
            text="{homeAddress.text}"/>
            </oh:ObjectHandles>

            <oh:ObjectHandles id="oh2" mouseCursors="{new ObjectHandlesMouseCursors()}" allowRotate="true" x="10" y="40" width="100" height="20" minHeight="1" minWidth="1" >
            <mx:TextArea
            borderColor="#FFFFFF"
            height="{oh2.height}"
            width="{oh2.width}"
            resize="true"
            x="0" y="0"
            fontWeight="bold"
            fontSize="15"
            fontFamily="{fontChoice.value}"

            color="{cp2.selectedColor}"
            text="{homeAddress2.text}"/>
            </oh:ObjectHandles>
            <mx:TextInput id="homeAddress"
            x="20" y="350" />

            <mx:TextInput id="testText"/>
            <!--text="{SelectionManager.instance.currentlySelected}"-->


            <mx:TextInput id="homeAddress2"
            x="20" y="400" />

            <mx:ColorPicker id="cp1"
            x="190"
            y="350" />

            <mx:ColorPicker id="cp2"
            x="190"
            y="400" />


            <mx:ComboBox x="220" y="350" id="fontChoice"
            dataProvider="{fontsArray}"
            change="changeEvt(event)"
            />





            <mx:Script>
            <![CDATA[
            import com.roguedevelopment.objecthandles.SelectionManager;
            ]]>
            </mx:Script>





            </mx:Application>

            [/code]


            What i want to happen is that when u change the combobox (id=fontChoice), I want the currently selected textArea's font to change,

            Cheers

            Tim
            • 3. Re: anyone used rogue development object handles
              Peter Hahmann Level 1
              Okay, like a RichTextEditor right?

              I think this is what you need:


              private function formatTxt():void{

              var start:int = my_textArea.selectionBeginIndex;
              var end:int = my_textArea.selectionEndIndex;
              var tRange:TextRange = new TextRange(my_textArea, true, start, end);
              tRange.fontFamily = my_comboBox.selectedItem.fontFamily;

              }

              Regards,
              Peter
              • 4. Re: anyone used rogue development object handles
                Seglespaan Level 1
                Yeah pretty much like a rich text editor but theres some other factors in the project that stop me using RTE

                So if i had 50 text areas could they all be changed using a single combo box?

                Basically when the user clicks text area one and then makes a change to combo box I want the text to change, then when they click text are 2, rotate it, move it and then change combo box the font changes, etc etc
                • 5. Re: anyone used rogue development object handles
                  Peter Hahmann Level 1
                  Yes, it can be done. If you notice the variable "my_textArea", this is the TextArea you intend to change, the only thing to do is passing this textarea to the method instead of using a default one:

                  private function formatTxt(selectedTextArea:TextArea):void{

                  var start:int = selectedTextAreaselectionBeginIndex;
                  var end:int = selectedTextArea.selectionEndIndex;
                  var tRange:TextRange = new TextRange(selectedTextArea, true, start, end);
                  tRange.fontFamily = my_comboBox.selectedItem.fontFamily;
                  }

                  Guess this solves your problem!

                  Regards,
                  Peter
                  • 6. Re: anyone used rogue development object handles
                    Seglespaan Level 1
                    Sorry to be a pain, but its getting the selected text area in order to target it thats my problem.
                    • 7. Re: anyone used rogue development object handles
                      Peter Hahmann Level 1
                      No problems!
                      Sorry but I'm not sure if I understood what you asked. You don't know how to get the TextArea on which you are working currently? Is it that? Well do the following:

                      <mx:Script>
                      <![CDATA[

                      private var curTextArea:TextArea;

                      private function txt_focusInHandler(e:FocusEvent):void{
                      curTextArea = e.target;
                      }

                      ]]>
                      </mx:Script>

                      <mx:TextArea focusIn="txt_focusInHandler(event)"/>

                      Now you can always use this variable you created, because every time you select a text in a TextArea the focus event will be dispatched and your variable will be updated to refer to your current TextArea.

                      regards,
                      Peter
                      • 8. Re: anyone used rogue development object handles
                        Peter Hahmann Level 1
                        Sorry, I forgot to say that this focusIn handler should be the same for each TextArea.

                        <mx:TextArea id = "txt1" focusIn="txt_focusInHandler(event)"/>
                        <mx:TextArea id = "txt2" focusIn="txt_focusInHandler(event)"/>
                        <mx:TextArea id = "txt3" focusIn="txt_focusInHandler(event)"/>
                        <mx:TextArea id = "txt4" focusIn="txt_focusInHandler(event)"/>
                        ....
                        and so on

                        Regards,
                        peter
                        • 9. Re: anyone used rogue development object handles
                          Seglespaan Level 1
                          I think thats the one I'm after, I'm off to try it out now,

                          I'll be sure to let u know how i get on,

                          Thanks very much for your help,

                          Tim
                          • 10. Re: anyone used rogue development object handles
                            Seglespaan Level 1
                            When I add the following code and try to compile I'm given the error,

                            Implicit coercion of a value with static type object to a possibly unrelated type mx.controls:TextArea.
                            • 11. Re: anyone used rogue development object handles
                              Peter Hahmann Level 1
                              You'll need to cast your target. Why?

                              Well event.target is type Object and your var is type TextArea. As both area diferent types you can't simply equal them, that is why in some cases we need to cast variables.

                              Try this:

                              private function txt_focusInHandler(e:FocusEvent):void{
                              curTextArea = e.target as TextArea;
                              }

                              Just complementing, casting improves code writing(and code hints) and avoids run-time errors since the compiler will be responsible for code checking.

                              Look at this example:

                              private var myText:String;

                              private function setText(e:MouseEvent):void{
                              myText = e.target.text;
                              }


                              private function setText2(e:MouseEvent):void{
                              myText = TextArea(e.target).text;
                              }

                              In the firs method e.target is a generic object so it will accept the text prop, in the second you will only access the properties from TextArea.


                              Regards,
                              peter
                              • 12. Re: anyone used rogue development object handles
                                Seglespaan Level 1
                                Ok so I've added the two functions suggested and it now compiles and runs fine, however the trace within the function txt_focusInHandler doesn't return anything, if I add the line
                                focusIn="txt_focusInHandler(event)"
                                to the Object Handles container the trace returns a value of Null, is this because flex thinks I'm clicking on the ObjectHandle rather than the text area??

                                Heres my Complete code!
                                • 13. Re: anyone used rogue development object handles
                                  Peter Hahmann Level 1
                                  As TextArea extends ScrollControlBase and ScrollControlBase extends UIComponent and so on, what is happening. If you set a breakpoint you'll see that e.target is not your TextArea but the UIComponent (this because of the event bubbling), so i'll have to use the currentTarget property, which refers to the "target" to whom the listener is added.

                                  Solution is: curTextArea = e.currentTarget as TextArea;

                                  regards,
                                  Peter
                                  • 14. Re: anyone used rogue development object handles
                                    Seglespaan Level 1
                                    Still returns null when i try to trace the selection of the textArea,

                                    Sorry for my ignorance but I'm somewhat new to flex.

                                    • 15. Re: anyone used rogue development object handles
                                      Peter Hahmann Level 1
                                      Try cleaning your browser cache and use this TextArea(e.currentTarget).

                                      I tested it with the currentTarget and it worked.

                                      regards,
                                      peter

                                      ps. if it still not worts, let me know!
                                      • 16. Re: anyone used rogue development object handles
                                        run,ryan! Level 3
                                        I use objecthandles, and SelectionManager.instance.currentSelected work for me.
                                        if you want to target the object inside the oh, it's probably selected.getChildAt(0)
                                        • 17. Re: anyone used rogue development object handles
                                          Seglespaan Level 1
                                          Thats what i tried to use initially but couldn't get it to work, (as per code in my second post)

                                          any ideas?
                                          • 18. Re: anyone used rogue development object handles
                                            run,ryan! Level 3
                                            SelectionManager.instance.currentlySelected(currentOH)
                                            humm... is that a different version of oh?
                                            currentlySelected is a property not a function of SelectionManager in my oh
                                            • 19. Re: anyone used rogue development object handles
                                              Seglespaan Level 1
                                              See i think the code above is a result of trial and error as i kept getting different results.

                                              Do u know how i would target the font family in the textArea of the currently selected oh?