Flex/AS3 problem

Pozdrav svim webmajstorima,

Da ne puno dužim, radim na jednoj flex aplikaciji, i naišao na dosad neriješiv problem.

Ako tko ima ikakvu ideju,prijedlog bio bi vrlo zahvalan.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"  >
    <fx:Script>
        <![CDATA[
 
            import spark.components.RichEditableText;
 
            [Bindable]public var selID:int;
            public var newID:int = new int(0)
 
            public var ret:RichEditableText;
            public var retTemp:RichEditableText;
 
            protected function theClick(event:Event):void{
 
                selID = event.target.id    
            }
 
 
            protected function btnAdd_clickHandler(event:MouseEvent):void{
 
                ret = new RichEditableText;
 
                ret.text = "Rich Text"
                ret.id = newID.toString()
                ret.addEventListener(MouseEvent.CLICK,theClick)
                hBox.addElementAt(ret,newID);
 
                newID++
            }
 
 
            protected function btnBold_clickHandler(event:MouseEvent):void{
 
                retTemp = hBox.getElementAt(selID) as RichEditableText
                retTemp.setStyle("fontWeight","bold");
                hBox.addElementAt(retTemp,selID);
            }
 
 
            protected function btnItalic_clickHandler(event:MouseEvent):void{
 
                retTemp = hBox.getElementAt(selID) as RichEditableText
                retTemp.setStyle("fontStyle","italic");
                hBox.addElementAt(retTemp,selID);
            }
 
        ]]>
    </fx:Script>
 
 
    <mx:Label x="10" y="24" text="Selected ID: {selID.toString()}" id="idTxt"/>
    <mx:HBox x="10" y="53" width="565" height="44" id="hBox"  verticalAlign="middle">
    </mx:HBox>
    <s:Button x="10" y="117" label="Add" id="btnAdd" click="btnAdd_clickHandler(event)"/>
    <s:Button x="193" y="117" label="Italic" id="btnItalic" click="btnItalic_clickHandler(event)" />
    <s:Button x="115" y="117" label="Bold" id="btnBold" click="btnBold_clickHandler(event)"/>
 
</s:Application>

Znaći ideja applikacije jest dinamičko dodavanje RichTexta, sa mogučnošću stilova(bold,italic, underline…) i kasnije drag, rotate,skew etc.

Svaki RichText tj. objekt mora imat svoj ID jer poslje trebam to renderirat u PDF.

No sve to stoji sa kodom gore postanim, jedino kada promjenim defaultni text RichEditableText-a njegov id nestane…

Unaprijed hvala…

Ne znam na šta misliš. Ali ako misliš na broj u slected ID polju onda se on meni mijenja. Počinje s 0 i kako se dodaje tako se broj uvećava za 1, a kad se vratim na neki on kreiranih kontrola on se(taj broj u selected ID polju) postavi na zadni ID broj odabranog rich text-a.

probaj nešto sa Repeater komponentom.

Čisto lupetanje,imaš u propertiesima opciju “Use flash text engine in mx components” pa stavi kvačicu,jer mislim da RET koristi novi FTE,a ti ga koristiš s hBox kontrolom koja je stara Halo(MX) komponenta(za razliku od HGroup ili BorderContainera s layoutom).

Ponavljam,čisto lupetanje u ove sitne sate…btw jesi probao s starom mx:RichTextEditor kontrolom?

Prvo zahvaljujem na svim odgovorima

@CreatifCode
znam da svaki child u hBox ima svoj “child Index”, te mogu addChild i addChildAt (ili addElementAt…)
No meni je do sada bio cilj da svaki child >ret< ima svoj unique id, nevezano sa Indexom, i to stoji sa app gore post-anom, no ponavljam problem nastaje što ret-ov id nestane nakon što promjenim text samog ret-a

@gorrc
…probao, ista stvar

@suludi
da… koristim hBox, al svejedno nije stvar u mx/spark komponentama, probao sam s s:BorderContainerm s:HGroup, s:Group… mx:Canvas itd,
probao i sa FTE in mx component, problem ostaje!

mx:RichTextEditor mi ne odgovara jer trebam imat jedan toolPanel sa kontrolama (Bold, Italic…) i n RET-ova koji se dragaju po stageu.

Ugl. da ne dužim:

skombinirao sam nešto sa UIComponent i mx:TextArea, i uspio

… jedino što mx:TextArea nema opciju auto fit content i neš setFocus() ne šljaka kak sam zamislio al da se to srediti

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"  >
	<fx:Script>
		<![CDATA[
			
			import mx.controls.Alert;
			import mx.controls.TextArea;
			import mx.core.UIComponent;

			
			public var ret:TextArea;
			public var retTemp:TextArea;
			public var uic:UIComponent;
			
			public var childCnt:Number

			private var window : UIComponent;
			private var originalPosition : Point;
			private var mouseDownPosition : Point;
			
			protected function theClick(event:Event):void{
				
				uic = UIComponent(event.currentTarget)
					
				retTemp = uic as TextArea

				if(retTemp.getStyle("fontWeight") == "bold"){
					btnBold.selected = true	
				}
				else{
					btnBold.selected = false	
				}

				hBox.addChild(retTemp)
			
			}
			
			private function theDrag( event : MouseEvent ) : void
			{
				
				window = uic
				this.systemManager.addEventListener( MouseEvent.MOUSE_MOVE, doMoving, true );
				this.systemManager.addEventListener( MouseEvent.MOUSE_UP, doCommitMove, true );									
				originalPosition = new Point( window.x, window.y );			
				mouseDownPosition = new Point( event.stageX, event.stageY );
			
			}
			
			private function doMoving( event : MouseEvent ) : void
			{						
				
				event.stopImmediatePropagation();
				
				var positionToMove : Point = new Point( originalPosition.x + ( event.stageX - mouseDownPosition.x ), 
					originalPosition.y + ( event.stageY - mouseDownPosition.y ) );
					window.move( positionToMove.x, positionToMove.y );
				
				hBox.addElement(retTemp)
			}
			
			private function doCommitMove( event : MouseEvent ) : void
			{		
				event.stopImmediatePropagation();	
				this.systemManager.removeEventListener( MouseEvent.MOUSE_MOVE, doMoving, true );
				this.systemManager.removeEventListener( MouseEvent.MOUSE_UP, doCommitMove , true );
			}
			
			protected function btnAdd_clickHandler(event:MouseEvent):void
			{
				ret = new TextArea;
				ret.text = "I'm text area"
				ret.addEventListener(MouseEvent.CLICK,theClick)
				ret.addEventListener(MouseEvent.MOUSE_DOWN,theDrag)

				hBox.addChild(ret);
				
				childCntTxt.text = "Number of items: " + hBox.numChildren.toString()
				
			}

			protected function btnBold_clickHandler(event:MouseEvent):void
			{
				if (retTemp.getStyle("fontWeight") == "bold"){
					retTemp.setStyle("fontWeight","normal");
				}
				else{
					retTemp.setStyle("fontWeight","bold");
				}
				hBox.addChild(retTemp)
			}

			protected function btnRemove_clickHandler(event:MouseEvent):void
			{
				hBox.removeChild(uic)
				childCntTxt.text = "Number of items: " + hBox.numChildren.toString()
			}

		]]>
	</fx:Script>
	
	<mx:Canvas id="hBox" width="558" height="286" x="10" y="39" backgroundColor="#E3E3E3">
	</mx:Canvas>
	
	<s:Button x="10" y="10" label="Add" id="btnAdd" click="btnAdd_clickHandler(event)" width="49"/>
	<s:Button x="63" y="10" label="Remove" id="btnRemove" click="btnRemove_clickHandler(event)"/>
	<s:ToggleButton x="364" y="9" label="Bold" selected="false" id="btnBold" click="btnBold_clickHandler(event)"/>
	<mx:Label x="442" y="10"  id="childCntTxt"/>
	
</s:Application>

poslje mogu sve childove utrpat u Array,
jer važno mi je da sve ret-ove mogu spremiti u db putem PHP-a sa svim svojim atriburima i kasnije ih vratit u flex

lp,


Copyright © 2020 WM Forum - AboutContact - Sponsored by: Mydataknox & Webmaster.Ninja