Flex zoom and scroll issue - actionscript-3

i am required to zoom a canvas through Hslider.
The problem is after zooming the canvas i cannot scroll to the extreme left and top of the canvas i.e some part of left and top canvas are not visible. i cannot find the reason.
The source code for the example is given below.
"
import mx.events.SliderEvent;
private function changeZoom(event:SliderEvent) : void
{
layout_cnv.scaleY = event.target.values[0]*2/100;
layout_cnv.scaleX = event.target.values[0]*2/100;
}
private function adjustDefaultZoom() : void
{
layout_cnv.scaleX = slider.values[0]/100*2;
layout_cnv.scaleY = slider.values[0]/100*2;
}
private function myDataTipFunc(val:String):String {
return String(val)+ "%";
}
]]>
</mx:Script>
<mx:Panel title="Zoom Demo" width="100%" height="100%">
<mx:Canvas id="canvas" width="100%" height="100%" horizontalScrollPosition="500">
<!--<mx:Image id="img" x="{canvas.width/2 - img.width/2}"
y="{canvas.height/2 - img.height/2}"
source="#Embed('../assets/products/Nokia_6630.png')"
creationComplete="adjustDefaultZoom()"
/>-->
<mx:Canvas visible="true" id="layout_cnv" creationComplete="adjustDefaultZoom()" borderStyle="solid" height="300"
width="500" verticalCenter="0" horizontalCenter="0"
verticalScrollPolicy="off" horizontalScrollPolicy="off" backgroundColor="#FFFFFF">
<mx:TextArea id="company_name_ta" visible="true" selectable="true" editable="true" height="20" backgroundAlpha="0.0" borderColor="#000000" width="200" fontSize="14"
borderStyle="solid" x="10" y="10" />
<mx:TextArea id="job_ta" height="20" selectable="true" borderColor="#000000" width="200" x="289" y="10" backgroundAlpha="0.0" textAlign="right"/>
<mx:TextArea id="fullname_ta" height="20" selectable="true" backgroundAlpha="0.0" borderColor="#000000" width="200" x="10" y="38" editable="true" enabled="true"/>
<mx:TextArea id="adress_line3_ta" height="20" selectable="true" backgroundAlpha="0.0" borderColor="#000000" width="200" x="10" y="268"/>
<mx:TextArea id="adress_line2_ta" height="20" selectable="true" backgroundAlpha="0.0" borderColor="#000000" width="200" x="10" y="240"/>
<mx:TextArea id="adress_line1_ta" height="20" selectable="true" backgroundAlpha="0.0" borderColor="#000000" width="200" y="212" x="10"/>
<mx:TextArea id="mobile_ta" height="20" selectable="true" backgroundAlpha="0.0" borderColor="#000000" width="200" x="289" y="40" textAlign="right"/>
<mx:TextArea id="fax_ta" height="20" selectable="true" backgroundAlpha="0.0" borderColor="#000000" width="200" y="68" x="289" textAlign="right"/>
<mx:TextArea id="email_ta" height="20" selectable="true" backgroundAlpha="0.0" borderColor="#000000" width="200" x="289" y="268" textAlign="right"/>
</mx:Canvas>
</mx:Canvas>
<mx:ControlBar horizontalAlign="center">
<mx:HSlider id="slider"
width="400"
minimum="1"
maximum="100"
labels="['0%','100%']"
values="[50]"
tickInterval="10"
snapInterval="1"
liveDragging="true"
change="changeZoom(event)"
dataTipFormatFunction="myDataTipFunc" />
</mx:ControlBar>
</mx:Panel>
"
please help .
Thanks in advance.

You wouldn't have this problem if instead of centering the zoomable canvas, you'd show it at coords in the top left part of its parent.
Alternatively you could calculate the needed coordinates, based on the size of its parent, and not let them drop below 0.
Here's code that will help:
private function calculateCoordinates() : void
{
var x : Number = (canvas.width - layout_cnv.width) / 2;
x = x < 0 ? 0 : x;
var y : Number = (canvas.height - layout_cnv.height) / 2;
y = y < 0 ? 0 : y;
layout_cnv.move(x, y);
}
All you have to do is add this method to your application and
this.callLater(calculateCoordinates);
at the end of your changeZoom and adjustDefaultZoom methods. Also remove align properties from layout_cnv.

Took a while to figure this one out. Seems that since you are using verticalCenter and horizontal center the canvas is being drawn outside of the viewable area. When running right-click and select 'show redraw regions' then you can clearly see that the canvas is outside of the area.
Once you remove the verticalCenter and horizontal center it seemed to be working (seeing all of the canvas while scrolling.)
On another note I don't see why you want two canvas in the same panel with nothing between them. Maybe this was just for your example.
Good luck

//Declare a variable
[Bindable]
public var myborderColor: ColorPicker = new ColorPicker();
private function init():void
{
myborderColor:.selectedColor = Color.WHITE ;
… …. in other function change the color
myborderColor:.selectedColor = Color.RED ;
mx:TextInput id=”myText” backgroundColor=”{numcasoborderColor.selectedColor}”

Related

as3 tilelist with custom itemrender add to selectedIndices

I create a TileList with custom renderer.
<s:BorderContainer
id="bcImage"
width="120"
height="99%"
borderVisible="true"
borderStyle="solid"
borderColor="#B3B3B3"
borderWeight="1"
cornerRadius="2"
backgroundAlpha=".8"
backgroundColor="#F8F8FF"
dropShadowVisible="true"
>
<mx:Canvas id="cvsImage" width="100%" click="cvsImage_clickHandler(event)">
<s:HGroup width="100%" paddingBottom="0" paddingTop="5" >
<s:CheckBox id="cbImgSelect"/>
<s:Label x="23" y="3" width="82" fontSize="11" fontWeight="normal" text="{data.imDate}"
textAlign="right" color="#000000"/>
</s:HGroup>
<mx:Image id="iconCanvas" x="10" y="20" width="99" height="99" horizontalAlign="center"
maintainAspectRatio="true" scaleContent="true"
verticalAlign="middle" mouseDown="iconCanvas_mouseDownHandler(event)"
>
</mx:Image>
</mx:Canvas>
<s:BorderContainer width="100%" y="124" height="25" bottom="1" left="3" right="3"
backgroundColor="#FFFFFF" id="bcTitre" borderAlpha="0" >
<s:VGroup width="100%" y="124" height="25" bottom="0" left="0" right="0"
paddingBottom="0" paddingTop="0" gap="0" click="iconCanvasLabel_mouseUp(event)">
<s:Label text="{data.imType}" height="50%" fontSize="10" paddingBottom="1" id="lType"
fontWeight="normal" width="99%" textAlign="center" toolTip="{data.imType}"/>
<s:Label text="{data.imStade}" fontSize="10" textAlign="center" paddingTop="1"
fontWeight="normal" width="99%" id="lStade" toolTip="{data.imStade}"/>
</s:VGroup>
</s:BorderContainer>
</s:BorderContainer>
My TileList has allowMultipleSelection enable.
I'd to check CheckBox when item is selected by click or by selection (continus or not) and if CheckBox.selected=true I'd like to show color selection around selected item.
Could you help me to do that ?
Best regards
It seems that you're trying to resolve the issue from opposite side, which is wrong
I suppose yo can consider following way:
set mouseEnabled to false for checkBox so that all the list item triggers click
alter default selection behaviour by intercepting changing event and doing something like
protected function lst_changingHandler(evt:IndexChangeEvent):void {
evt.preventDefault();
var ids:Vector.<int> = (evt.currentTarget as List).selectedIndices;
(evt.currentTarget as List).selectedIndices = ids.concat(new <int>[evt.newIndex]);
bind checkBox selected state to the renderer selected one

how to get id of BorderContainer at runtime in Flex

I am getting error while attempting to get id of BorderContainer at runtime. I tried using getStyle but it is also failing.
<s:Panel id="colorPanel"
title="Dem display color"
width="500" height="500">
<s:layout>
<s:BasicLayout/>
</s:layout>
<s:Label id="label" y="4" horizontalCenter="0"/>
<s:BorderContainer id="Box1" x="70" y="70" height="50" width="50" backgroundColor="#0000ff">
</s:BorderContainer>
<s:BorderContainer id="Box2" x="90" y="90" height="51" width="50" backgroundColor="#00ff00">
</s:BorderContainer>
<s:BorderContainer id="Box3" x="50" y="50" height="52" width="50" backgroundColor="#ff0000">
</s:BorderContainer>
<s:Button label="Click" click="
colorPanel.setElementIndex(colorPanel.getElementAt(0),3);
label.text = ""+colorPanel.getElementAt(0).id ;
">
</s:Button>
</s:Panel>
Instead of casting to BorderContainer, it is safe to cast to UIComponent. In your example it crashes when the returned element is Label instead of BorderContainer. You can do as below:
<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script><![CDATA[
import mx.core.UIComponent;
]]></fx:Script>
<s:Panel id="colorPanel"
title="Dem display color"
width="500" height="500">
<s:layout>
<s:BasicLayout/>
</s:layout>
<s:Label id="label" text="Red" y="4" horizontalCenter="0"/>
<s:BorderContainer id="Blue" x="70" y="70" height="50" width="50" backgroundColor="#0000ff">
</s:BorderContainer>
<s:BorderContainer id="Green" x="90" y="90" height="51" width="50" backgroundColor="#00ff00">
</s:BorderContainer>
<s:BorderContainer id="Red" x="50" y="50" height="52" width="50" backgroundColor="#ff0000">
</s:BorderContainer>
<s:Button label="Click" click="{
colorPanel.setElementIndex(colorPanel.getElementAt(1),3);
label.text = UIComponent(colorPanel.getElementAt(3)).id;}"/>
</s:Panel>
</s:Application>
Solution I found seems like over rigidness on the part of Adobe. I was able to get value of Id the moment I casted the returned Element as BorderContainer. So we have to live with it till Adobe lowers it's compiler's expectations from us.
label.text = ""+ BorderContainer(colorPanel.getElementAt(0)).id ;

how can I call mxml application from actionscript [duplicate]

This question already has an answer here:
how to call mxml application from action script
(1 answer)
Closed 9 years ago.
I've main.mxml which has login button. It looks like below -
<mx:Script>
<![CDATA[
private function onSuccessfulLogin(event):void {
// How to call second mxml application*/
}
]]>
</mx:Script>
<mx:Panel x="414" y="145" width="355" height="200" layout="absolute"
title="Enter Your Login Information">
<mx:TextInput id="textInputName" x="147" y="12"/>
<mx:TextInput id="textInputPassword" x="147" y="57"/>
<mx:Button x="142" y="115" label="Login" id="callToServer"
<mx:Label x="37" y="14" text="User Name"/>
<mx:Label x="41" y="59" text="Password"/>
</mx:Panel>
Now on successful login I want to call another mxml application, for example second.mxml. It looks like -
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns="*" creationComplete="iFrame.visible=true"
viewSourceURL="srcview/index.html">
<mx:HBox width="100%" height="100%">
<mx:Panel title="/ Company Home" width="200" height="100%" >
<mx:Tree id="tree" width="100%" height="100%" dataProvider="{treeData}"
labelField="#label" showRoot="false"
change="iFrame.source =
(Tree(event.target).selectedItem.attribute('path').toString());" />
</mx:Panel>
<mx:Panel width="100%" height="100%" title="Ticket Details" >
<IFrame id="iFrame" source="some url" width="100%" height="100%" />
</mx:Panel>
</mx:HBox>
</mx:Application>
Please let me know how will I do it. Thanks for your help!
One simple way to let 2 Applications communicate would be LocalConnectionDocumentation here

flex4 add group with transition effect

How can i add a Group (with unknown size) to SkinnableContainer with a transformation effect?
Example
First, resize the SkinnableContainer smoothly to its final size and then fade in the Group.
Problem hereby
The Group-size is determined by adding it to the SkinnableContainer. Doing this, the SkinnableContainer gets the final size and the Group is shown, without playing the transition effect.
All examples i found are MXML- and State-based. But i need an Actionscript-only solution here.
<fx:Declarations>
<s:Parallel id="showEff">
<s:Rotate3D angleYFrom="-90" angleYTo="0" duration="7000"/>
<s:Fade alphaFrom="0.0" alphaTo="1.0" duration="7000" />
<mx1:WipeRight duration="9000"/>
</s:Parallel>
<s:Parallel id="hideEff">
<s:Rotate3D angleYFrom="0" angleYTo="-90" duration="4000" />
<s:Fade alphaFrom="1.0" alphaTo="0.0" duration="7000"/>
<mx1:WipeRight duration="5000"/>
</s:Parallel>
</fx:Declarations>
<s:Button id="btn"
label="Toggle Panel visibility"
click="skinnableContainerPanel.visible = !skinnableContainerPanel.visible;" />
<s:Panel id="skinnableContainerPanel" title="Using SkinnableContainer"
width="500" height="300" showEffect="{showEff}"
hideEffect="{hideEff}" >
<s:layout>
<s:VerticalLayout gap="10" verticalAlign="middle"
horizontalAlign="center"/>
</s:layout>
<s:SkinnableContainer
skinClass="com.SkinnableContainerSkin"
width="50%" height="50%" horizontalCenter="0"
verticalCenter="0">
<s:HGroup horizontalCenter="0" verticalCenter="0" >
<s:BorderContainer width="50" height="50"
borderWeight="2" color="0x323232" />
<s:BorderContainer width="50" height="50"
borderWeight="2" color="0x323232" />
<s:BorderContainer width="50" height="50"
borderWeight="2" color="0x323232" />
</s:HGroup>
</s:SkinnableContainer>
</s:Panel>

Using dynamic id's or name's to change text of a label

I have a flex app I'm working on and want to be able to loop thru a series of labels and assign the text for them
kinda like
var labelnum:String = "1013";
var elem:Label = this["label" + labelnum];
elem.text = "this one";
example of the grid items... I have both name and id set
<mx:GridItem width="100%" height="100%">
<mx:Label text="1005" id="label1005" name="label1005" />
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:Label text="1006" id="label1006" name="label1006" />
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:Label text="1007" id="label1007" name="label1007" />
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:Label text="1008" id="label1008" name="label1008" />
</mx:GridItem>
What is the proper way to access these labels and change the text?