FileSystemTree itemRenderer - actionscript-3

I've been trying to do a couple of things and I couldn't.
I've been trying to skin a mx:FileSystemTree, to show de data horizontally, I think it's almost impossible, anyone has an idea how to make it?
The second thing I'm trying is to add an itemRenderer to the FileSystemTree wanting to add a pair of buttons(add and delete, which I already had working). Everything I tried so far is giving the same error:
TypeError: Error #1034: Type Coercion failed: cannot convert SKins::FileSystemItemRenderer#971c479 to mx.controls.listClasses.IListItemRenderer.
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="750" height="500">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:VGroup width="607" height="134">
<s:HGroup width="607" height="68">
<s:Button label="Button"/>
<s:Button label="Button"/>
</s:HGroup>
<s:TextInput width="600"/>
</s:VGroup>
<mx:HDividedBox>
<mx:FileSystemTree id="tree" width="615" height="480" allowMultipleSelection="true"
borderVisible="false" defaultLeafIcon="#Embed('../assets/folder.png')"
directory="{new File(raiz)}" dragEnabled="true" dropEnabled="true"
folderClosedIcon="#Embed('../assets/folder.png')"
folderOpenIcon="#Embed('../assets/openFolder.png')" fontSize="45"
fontStyle="normal" fontWeight="normal" iconFunction="selectIcon"
itemRenderer="SKins.FileSystemItemRenderer" showIcons="true"
textAlign="left" textDecoration="none" verticalAlign="middle"/>
</mx:HDividedBox>
</s:WindowedApplication>
That's the code which is going to show the tree.
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true">
<s:Label text="{data}"/>
</s:ItemRenderer>
I have tried with a simple renderer receiving the error #1034.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/04/08/creating-an-alternating-item-renderer-in-a-spark-list-control-in-flex-4/ -->
<s:MXTreeItemRenderer name="IListItemRenderer"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:HGroup id="hGr" left="4" right="4" top="4" bottom="4">
<s:RichText id="lbl" text="({itemIndex}) {data.label}" width="100%" />
<mx:Image id="img" source="{data.img}" toolTip="{data.img}" width="100" height="67" />
</s:HGroup>
</s:MXTreeItemRenderer>
I also have tried another renderer, but with the same results.

Not sure about showing data horizontally, but your 2nd point about itemrenderer is working fine for me. Here is the working code
<?xml version="1.0" encoding="utf-8"?>
<s:MXTreeItemRenderer
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:HGroup id="hGr" left="4" right="4" top="4" bottom="4">
<s:Rect id="indentationSpacer"
width="{treeListData.indent}" height="22"
alpha="0">
<s:fill>
<s:SolidColor color="0xFFFFFF" />
</s:fill>
</s:Rect>
<s:Group id="disclosureGroup">
<s:BitmapImage source="{treeListData.disclosureIcon}"
width="16" height="16"
visible="{treeListData.hasChildren}" />
</s:Group>
<s:BitmapImage source="{treeListData.icon}"
width="16" height="16"/>
<s:RichText id="lbl" text="{data.nativePath}" toolTip="{data.nativePath}" width="100%" maxDisplayedLines="1" />
<s:Button label="Button"/>
<s:Button label="Button"/>
</s:HGroup>

Related

Why does this non-descriptive error happen when I try to build this mxml file?

I get the following error when trying to build a simple MXML file:
Build halted with errors (fcsh).
Here is the MXML:
<?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">
<s:Label id="titleLabel" x="50" y="50" fontFamily="Arial" fontWeight="bold" text="My first Flex 4 application"/>
<fx:Script>
<![CDATA[
public function example() {
speakTextInput.text = "This is an example of horrible code!";
}
]]>
</fx:Script>
<s:HGroup x="50" y="70" width="80%">
<s:Button id="speakButton" label="Say Something!" />
<s:TextInput id="speakTextInput" width="100%" text="" />
</s:HGroup>
</s:Application>
Maybe your compiler doesn't like functions without type declaration for return value. Try change to:
public function example():void

Flex: Spark image resize does not work

When I use resize component on image, it just disappears. Even if I give widthTo and heightTo values more than image size.
Code
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:net="flash.net.*">
<fx:Script>
<![CDATA[
import mx.effects.Resize;
import mx.utils.ObjectUtil;
private function btn_click(evt:MouseEvent):void {
var arr:Array = [];
arr.push(new FileFilter("Images", ".gif;*.jpeg;*.jpg;*.png"));
fileReference.browse(arr);
}
private function fileReference_select(evt:Event):void {
fileReference.load();
}
private function fileReference_complete(evt:Event):void {
img.source = fileReference.data;
}
]]>
</fx:Script>
<fx:Declarations>
<net:FileReference id="fileReference"
select="fileReference_select(event);"
complete="fileReference_complete(event);" />
<s:Resize id="resizeBig"
target="{img}"
widthFrom="{img.width}" widthTo="{newWidth.text as Number}"
heightFrom="{img.height}" heightTo="{newHeight.text as Number}"/>
<s:Resize id="myResizeEffect"
target="{img}"
widthBy="10" heightBy="10"/>
</fx:Declarations>
<s:Image id="img"
verticalCenter="0"
horizontalCenter="0"
maxWidth="200"
maxHeight="200"
/>
<mx:ControlBar>
<mx:Button id="btn"
label="Upload"
click="btn_click(event);" />
<s:HGroup verticalAlign="middle">
<s:Label>Width:</s:Label>
<!-- <s:NumericStepper id="newWidth" minimum="1" maximum="100" value="10" /> -->
<s:TextInput id="newWidth" restrict="0-9.\\-" />
</s:HGroup>
<s:HGroup verticalAlign="middle">
<s:Label>Height:</s:Label>
<s:TextInput id="newHeight" restrict="0-9.\\-"/>
</s:HGroup>
<s:HGroup verticalAlign="middle">
<s:Button id="resize"
label="Resize"
click="resizeBig.end();resizeBig.play();"
/>
<s:Button label="Resize Me"
click="myResizeEffect.end();myResizeEffect.play();"/>
</s:HGroup>
</mx:ControlBar>
</s:WindowedApplication>
I think the binding expression doesn't like the "as Number" thing. I would try with a function that does the conversion:
widthTo="{getNumber(newWidth.text)}"

Simple datagroup with itemrenderer not working in flex mobile

I am using a datagroup for displaying XML data. When I am using default item renderer the nodes are displaying, but when I try with my own itemrenderer, it fails. Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
<s:layout>
<s:VerticalLayout paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10"/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
]]>
</fx:Script>
<fx:Declarations>
<fx:XML id="DataXml" source="Data.xml"/>
</fx:Declarations>
<s:Label text="Start"/>
<s:Scroller>
<s:DataGroup width="100%" height="100%" itemRenderer="views.DataItemRenderer"
dataProvider="{new XMLListCollection(DataXml.children())}" >
<s:layout>
<s:VerticalLayout/>
</s:layout>
</s:DataGroup>
</s:Scroller>
<s:Label text="end"/>
</s:View>
Item renderer::::
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
width="100%" >
<fx:Declarations>
<s:HGroup width="100%">
<s:Label id="txtFirstName" text="Name::"/>
<s:Label id="locationTxt" text="LOcation::"/>
<s:Label id="packTxt" text="Package::"/>
<s:Label id="experienceTxt" text="Experience::"/>
<s:Label id="designationTxt" text="Designation::"/>
</s:HGroup>
</fx:Declarations>
<fx:Script>
<![CDATA[
override public function set data(value:Object):void {
txtFirstName.text += value.firstName;
locationTxt.text += value.location;
packTxt.text += value.pack;
experienceTxt.text += value.experience;
designationTxt.text += value.designation;
}
]]>
</fx:Script>
</s:ItemRenderer>
XML File::
<?xml version="1.0" encoding="UTF-8"?>
<data>
<employee>
<firstname>Bujji</firstname>
<location>Hyderabad</location>
<pack>28000</pack>
<experience>1year</experience>
<designation>ASE</designation>
</employee>
<employee>
<firstname>Tanuja</firstname>
<location>Hyderabad</location>
<pack>25000</pack>
<experience>2Year</experience>
<designation>ASE</designation>
</employee>
<employee>
<firstname>Sarath</firstname>
<location>Banglore</location>
<pack>12000</pack>
<experience>1Year</experience>
<designation>JSE</designation>
</employee>
</data>
The issue is in the ItemRenderer file. You've got your s:HGroup inside the fx:Declerations tag. Place it outside and it should be fine.
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
width="100%" >
<s:HGroup width="100%">
<s:Label id="txtFirstName" text="Name::"/>
<s:Label id="locationTxt" text="LOcation::"/>
<s:Label id="packTxt" text="Package::"/>
<s:Label id="experienceTxt" text="Experience::"/>
<s:Label id="designationTxt" text="Designation::"/>
</s:HGroup>
</s:ItemRenderer>
NB: The declerations tag is for non-visual elements. (See adobe docs)
The following item renderer works for me:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
width="100%" height="20">
<s:HGroup width="100%">
<s:Label id="txtFirstName"/>
<s:Label id="locationTxt"/>
<s:Label id="packTxt"/>
<s:Label id="experienceTxt"/>
<s:Label id="designationTxt"/>
</s:HGroup>
<fx:Script>
<![CDATA[
override public function set data(value:Object):void {
super.data = value;
trace("Name: " + value.firstname);
txtFirstName.text = "Name: " + value.firstname;
locationTxt.text = "Location: " + value.location;
packTxt.text = "Package: " + value.pack;
experienceTxt.text = "Experience: " + value.experience;
designationTxt.text = "Designation: " + value.designation;
}
]]>
</fx:Script>
</s:ItemRenderer>

How to mirror camera display in VideoDisplay in Flex

I am trying to mirror the camera display in my mx:VideoDisplay object in Flex 3.6. That is, I want the camera image to be flipped horizontally.
This is my MXML file:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" applicationComplete="init()"
xmlns:ns1="components.*"
xmlns:ns2="*"
xmlns:fl="flash.media.*"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:gauge="components.gauge.*"
>
<mx:Script source="script.as" />
<mx:Style source="style.css" />
<mx:Canvas label="recorder" width="100%" height="100%" verticalScrollPolicy="off"
horizontalScrollPolicy="off" id="canvas2">
<mx:VideoDisplay id="myWebcam" scaleX="1" left="0" top="0" bottom="36" right="0"/>
<mx:Image id="mask2" source="#Embed(source='assets/mask.png')"
left="190" top="120" width="270"/>
<ns1:VideoContainer right="0" bottom="0" />
</mx:Application>
I have tried to use myWebcam.scaleX="-1" and adding myWebcam.x = myWebcam.width among many further combinations without success.
So, how am I supposed to flip the image?
Thanks
You can change:
<mx:VideoDisplay id="myWebcam" scaleX="1" left="0" top="0" bottom="36" right="0"/>
to:
<mx:VideoDisplay id="myWebcam" scaleX="-1" left="0" top="0" bottom="36" right="0" x="{myWebcam.width + myWebcam.x}"/>
I also found that myWebcam.scaleX = -1 is not ok, maybe it is a bug.

Flex / AS3: how to set properties of spark Rect in ActionScript?

I have a Flex application in which I draw a rectangle using:
<s:Rect height="20" width="115" top="1" id="myRect">
<s:stroke>
<s:SolidColorStroke color="#FF0000" weight="2" alpha="0"/>
</s:stroke>
</s:Rect>
I want to set the value of alpha for myRect dynamically. Is it possible to set alpha using Actionscript? If so, how to access the alpha property?
I thought something like this would work, but I'm getting error Access of undefined property SolidColorStroke:
searchRect.stroke.SolidColorStroke.alpha=1;
Give the s:SolidColorStroke an id, as in:
<s:SolidColorStroke id="stroke"
Then you can set alpha such as:
stroke.alpha = 0.5;
This example updates the alpha based on a slider:
<?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">
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:Rect height="20"
width="115"
top="1"
id="myRect">
<s:stroke>
<s:SolidColorStroke id="stroke"
color="#FF0000"
weight="2"
alpha="0" />
</s:stroke>
</s:Rect>
<s:HSlider id="slider"
valueCommit="{stroke.alpha = slider.value}"
value="0.5"
minimum="0"
maximum="1"
stepSize="0.1"
snapInterval="0.1" />
</s:Application>