I have a mx:list with custom itemrenderer.
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox 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="100%" height="100%"
horizontalScrollPolicy="off" verticalScrollPolicy="off"
>
<fx:Declarations>
<!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). -->
</fx:Declarations>
<fx:Script>
<![CDATA[
/* part with no warning
[Bindable] var tName:String;
override public function set data(value:Object):void
{
acID.text = value.id;
acGlob.text = value.glob;
acVisiO.text = value.visibO;
acVisiV.text = value.visibV;
acRoot.text = value.root;
//acPhoto.source = value.photo;
//acName.text = value.name;
tName = value.name
}
override public function get data():Object
{
return super.data;
} */
]]>
</fx:Script>
<mx:states>
<mx:State name="normal"/>
<mx:State name="hovered"/>
<mx:State name="selected"/>
</mx:states>
<mx:Image source="{data.photo}" width="20" height="20" alpha.hovered=".5"/>
<mx:Label text="{data.name}"
color.hovered="0x1313cd" color.selected="0x000000" color.normal="#000000"
toolTip="{data.name}"
/>
<mx:Label visible="false" width="0" height="0" id="acID" />
<mx:Label visible="false" width="0" height="0" id="acGlob"/>
<mx:Label visible="false" width="0" height="0" id="acVisiO"/>
<mx:Label visible="false" width="0" height="0" id="acVisiV"/>
<mx:Label visible="false" width="0" height="0" id="acRoot" />
</mx:HBox>
If I use set data function, no warning appear. But in this case I don't know how to access on itemrenderer data on doublickclik.
arrList = new ArrayList(list);
listAcc = new List();
listAcc.percentHeight = 100;
listAcc.percentWidth =100;
listAcc.itemRenderer = new ClassFactory(irMxList);
listAcc.doubleClickEnabled = true;
listAcc.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, onItemDoubleClick);
listAcc.dataProvider = arrList;
My problem is that an error appear if I try to access on itemrenderer.data
private function onItemDoubleClick(event:ListEvent):void {
var label:String = event.itemRenderer.data.name;
var index:String = event.itemRenderer.data.id;
var glob:String = event.itemRenderer.data.glob;
var visuO:String = event.itemRenderer.data.visibO;
var visuV:String = event.itemRenderer.data.visibV;
var rootFile:String = event.itemRenderer.data.root;
}
Thanks for helping
private function onItemDoubleClick(event:ListEvent):void {
var data:Object = arrList.getItemAt(event.rowIndex);
var label:String = data.name;
var index:String = data.id;
var glob:String = data.glob;
var visuO:String = data.visibO;
var visuV:String = data.visibV;
var rootFile:String = data.root;
}
Find below a solution
private function onItemDoubleClick(event:ListEvent):void {
var label:String = event.itemRenderer.data.name;
var index:String = event.itemRenderer.data.id;
var glob:String = event.itemRenderer.data.glob;
var visuO:String = event.itemRenderer.data.visibO;
var visuV:String = event.itemRenderer.data.visibV;
var rootFile:String = event.itemRenderer.data.root; }
ItemRenderer code is
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox 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="100%" height="100%"
horizontalScrollPolicy="off" verticalScrollPolicy="off"
>
<fx:Declarations>
<!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private var _data:Object;
override public function set data(value:Object):void {
acID.text = value.id;
acGlob.text = value.glob;
acVisiO.text = value.visibO;
acVisiV.text = value.visibV;
acRoot.text = value.root;
acPhoto.source = value.photo;
acName.text = value.name;
_data = value;
}
override public function get data():Object {
return _data;
}
]]>
</fx:Script>
<mx:states>
<mx:State name="normal"/>
<mx:State name="hovered"/>
<mx:State name="selected"/>
</mx:states>
<!--<mx:Image source="{data.photo}" width="20" height="20" alpha.hovered=".5"/>
<mx:Label text="{data.name}"
color.hovered="0x1313cd" color.selected="0x000000" color.normal="#000000"
toolTip="{data.name}"
/>-->
<mx:Image id="acPhoto" width="20" height="20" alpha.hovered=".5"/>
<mx:Label id="acName"
color.hovered="0x1313cd" color.selected="0x000000" color.normal="#000000"
toolTip="{acName.text}"
/>
<mx:Label visible="false" width="0" height="0" id="acID" />
<mx:Label visible="false" width="0" height="0" id="acGlob"/>
<mx:Label visible="false" width="0" height="0" id="acVisiO"/>
<mx:Label visible="false" width="0" height="0" id="acVisiV"/>
<mx:Label visible="false" width="0" height="0" id="acRoot" />
</mx:HBox>
Thanks everybody
Related
This code plays Youtube videos. The file works using Debug or Run buttons in FlashBuilder but has a bug when played from a web server or from the Export Release folder: when the second video runs the audio from the first video keeps playing. How can I unload the first audio?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.SWFLoader;
private var swfLoader:SWFLoader;
[Bindable] public var videoToPlay:String
public function playVideo(videoNum:int):void
{
if(swfLoader)
{
swfLoader.autoLoad = false;
swfLoader.unloadAndStop();
hg.removeChild(swfLoader);
SoundMixer.stopAll();
}
var videoAddress:String
if(videoNum == 1){
videoAddress = "m2dg6teC7fg";
}else{
videoAddress = "0QRO3gKj3qw";
}
videoToPlay = "https://www.youtube.com/v/VIDEO_ID?v=" + videoAddress;
play();
}
public function play():void
{
swfLoader = new SWFLoader();
swfLoader.y = 100;
swfLoader.load(videoToPlay);
hg.addChild(swfLoader);
}
]]>
</mx:Script>
<mx:HBox id="hg">
<mx:Button id="button1" y="50" label="Button1" click="playVideo(1)" useHandCursor="true" buttonMode="true" />
<mx:Button id="button2" y="50" label="Button2" click="playVideo(2)" useHandCursor="true" buttonMode="true" />
</mx:HBox>
</mx:Application>
The solution to stop first video/audio on second button click is:
Use following in your code to unload first video from swfloader:
<fx:Script>
<![CDATA[
import mx.controls.SWFLoader;
private var swfLoader:SWFLoader;
[Bindable] public var videoToPlay:String
public function playVideo(videoNum:int):void
{
if(swfLoader)
{
swfLoader.autoLoad = false;
swfLoader.unloadAndStop();
// swfLoader.autoLoad = true;
hg.removeElement(swfLoader);
SoundMixer.stopAll();
}
var videoAddress:String
if(videoNum == 1){
videoAddress = "m2dg6teC7fg";
}else{
videoAddress = "0QRO3gKj3qw";
}
videoToPlay = "https://www.youtube.com/v/VIDEO_ID?v=" + videoAddress;
play();
}
public function play():void
{
swfLoader = new SWFLoader();
swfLoader.y = 100;
swfLoader.load(videoToPlay);
hg.addElement(swfLoader);
}
]]>
</fx:Script>
<s:HGroup id="hg">
<s:Button id="button1" y="50" label="Button1" click="playVideo(1)" useHandCursor="true" buttonMode="true" />
<s:Button id="button2" y="50" label="Button2" click="playVideo(2)" useHandCursor="true" buttonMode="true" />
</s:HGroup>
I have edited code below, which works for your problem(I tested it my side). Try it and let me know it's works?
Edit:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:Script>
<![CDATA[
import mx.controls.SWFLoader;
private var swfLoader:SWFLoader;
[Bindable] public var videoToPlay:String
public function playVideo(videoNum:int):void
{
if(swfLoader)
{
swfLoader.source = "";
swfLoader.load(null);
SoundMixer.stopAll();
}
var videoAddress:String
if(videoNum == 1){
videoAddress = "m2dg6teC7fg";
}else{
videoAddress = "0QRO3gKj3qw";
}
videoToPlay = "https://www.youtube.com/v/VIDEO_ID?v=" + videoAddress;
play();
}
public function play():void
{
swfLoader = new SWFLoader();
swfLoader.y = 100;
swfLoader.load(videoToPlay);
hg.addChild(swfLoader);
}
private function onRemove():void
{
}
]]>
</mx:Script>
<mx:HBox id="hg">
<mx:Button id="button1" y="50" label="Button1" click="playVideo(1)" useHandCursor="true" buttonMode="true" />
<mx:Button id="button2" y="50" label="Button2" click="playVideo(2)" useHandCursor="true" buttonMode="true" />
</mx:HBox>
</mx:Application>
I am using a AxisRenderer with rotateLabels canDropLabels for my CategoryAxis and the labels are appearing microscopic. I can show every other label just fine, but the labels do not enlarge. I have provided an full example below. If you need the Ubuntu font you can download it here or use your own. The CategoryAxis should show every 3 labels.
<?xml version="1.0"?>
<!-- Derrived From: http://livedocs.adobe.com/flex/3/html/help.html?content=charts_types_06.html -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="init(event)" width="90%" height="60%">
<mx:Style>
#namespace mx "http://www.adobe.com/2006/mxml";
#font-face{
src: url("../assets/Ubuntu.ttf");
fontFamily:Ubuntu;
embedAsCFF:false;
advancedAntiAliasing:true;
}
mx|ColumnChart {
fontFamily:Ubuntu;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
import mx.formatters.DateFormatter;
public static const msPerSecond:uint = 1000;
public static const msPerMinute:uint = msPerSecond * 60;
public static const msPerHour:uint = msPerMinute * 60;
public static const msPerDay:uint = msPerHour * 24;
public static const msPerWeek:uint = msPerDay * 7;
protected var formatter:DateFormatter;
private var currIndex:uint = 0;
[Bindable]
public var expenses:ArrayCollection;
protected function init(event:FlexEvent):void {
formatter = new DateFormatter();
formatter.formatString = 'MM/DD';
generateExpenses();
}
private function generateExpenses():void {
var now:Date = new Date(), d:Date;
expenses = new ArrayCollection();
// The next 60 days inclusive
for (var i:uint = 0; i < 60; i++) {
d = new Date();
d.time = now.time+i*msPerDay;
var r:uint = rand(100, 1000);
var o:uint = rand(1, 100);
expenses.addItem({
'date':d,
'profit':r,
'expenses':rand(r-o, r+o)
});
}
}
public function categoryLabel(val:Object, prev:Object,
axis:CategoryAxis, item:Object):String {
var index:uint = currIndex;
currIndex++;
return showLabel(index, axis.dataProvider.length, 20) ?
formatter.format(val) : '';
}
private function rand(lb:int, ub:int):Number {
return Math.floor(Math.random() * (1 + ub - lb)) + lb;
}
private function showLabel(index:uint, max:uint, interval:uint):Boolean {
return index % int(Math.ceil(max/interval)) == 0;
}
]]>
</mx:Script>
<!-- Define custom colors for use as column fills. -->
<mx:SolidColor id="sc1" color="0x00FF00" alpha=".3"/>
<mx:SolidColor id="sc2" color="0xFF0000" alpha=".3"/>
<!-- Define custom Strokes for the columns. -->
<mx:SolidColorStroke id="s1" color="0x00FF00" weight="2"/>
<mx:SolidColorStroke id="s2" color="0xFF0000" weight="2"/>
<mx:Panel title="ColumnChart Control with Custom Column Styles"
width="100%" height="100%">
<mx:HBox width="100%" height="100%">
<mx:Legend dataProvider="{myChart}"/>
<mx:ColumnChart id="myChart" dataProvider="{expenses}" showDataTips="true"
width="100%" height="100%" gutterBottom="50">
<mx:horizontalAxis>
<mx:CategoryAxis id="cAxis" dataProvider="{expenses}"
categoryField="date" labelFunction="categoryLabel"/>
</mx:horizontalAxis>
<mx:horizontalAxisRenderers>
<mx:AxisRenderer axis="{cAxis}" labelRotation="{-25}"
canStagger="false" canDropLabels="true" fontSize="20"/>
</mx:horizontalAxisRenderers>
<mx:series>
<mx:ColumnSeries
xField="date"
yField="profit"
displayName="Profit"
fill="{sc1}"
stroke="{s1}"
/>
<mx:ColumnSeries
xField="date"
yField="expenses"
displayName="Expenses"
fill="{sc2}"
stroke="{s2}"
/>
</mx:series>
<mx:verticalAxis>
<mx:LinearAxis id="lAxis"/>
</mx:verticalAxis>
</mx:ColumnChart>
</mx:HBox>
</mx:Panel>
</mx:Application>
Hi Please modify your code as below:- The CategoryAxis will show every 3 labels.
<?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"
initialize="init(event)" >
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:SolidColor id="sc1" color="0x00FF00" alpha=".3"/>
<mx:SolidColor id="sc2" color="0xFF0000" alpha=".3"/>
<!-- Define custom Strokes for the columns. -->
<mx:SolidColorStroke id="s1" color="0x00FF00" weight="2"/>
<mx:SolidColorStroke id="s2" color="0xFF0000" weight="2"/>
</fx:Declarations>
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
#font-face{
src: url("../assets/Ubuntu.ttf");
fontFamily:Ubuntu;
embedAsCFF:false;
advancedAntiAliasing:true;
}
mx|ColumnChart {
fontFamily:Ubuntu;
}
</fx:Style>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
import mx.formatters.DateFormatter;
public static const msPerSecond:uint = 1000;
public static const msPerMinute:uint = msPerSecond * 60;
public static const msPerHour:uint = msPerMinute * 60;
public static const msPerDay:uint = msPerHour * 24;
public static const msPerWeek:uint = msPerDay * 7;
protected var formatter:DateFormatter;
private var currIndex:uint = 0;
[Bindable]
public var expenses:ArrayCollection;
protected function init(event:FlexEvent):void {
formatter = new DateFormatter();
formatter.formatString = 'MM/DD';
generateExpenses();
}
private var dataToShow:uint = 60;
private function generateExpenses():void {
var now:Date = new Date(), d:Date;
expenses = new ArrayCollection();
// The next 60 days inclusive
for (var i:uint = 0; i < dataToShow; i++) {
d = new Date();
d.time = now.time+i*msPerDay;
var r:uint = rand(100, 1000);
var o:uint = rand(1, 100);
expenses.addItem({
'date':d,
'profit':r,
'expenses':rand(r-o, r+o)
});
}
}
public function categoryLabel(val:Object, prev:Object,
axis:CategoryAxis, item:Object):String {
var index:uint = currIndex;
currIndex++;
return showLabel(index, axis.dataProvider.length, dataToShow) ?
formatter.format(val) : '';
}
private function rand(lb:int, ub:int):Number {
return Math.floor(Math.random() * (1 + ub - lb)) + lb;
}
private function showLabel(index:uint, max:uint, interval:uint):Boolean {
return index % int(Math.ceil(max/interval)) == 0;
}
]]>
</fx:Script>
<mx:Panel title="ColumnChart Control with Custom Column Styles"
width="100%" height="100%">
<mx:HBox width="100%" height="100%">
<mx:Legend dataProvider="{myChart}"/>
<mx:ColumnChart id="myChart" dataProvider="{expenses}" showDataTips="true"
width="100%" height="100%" gutterBottom="50">
<mx:horizontalAxis>
<mx:CategoryAxis id="cAxis" dataProvider="{expenses}"
categoryField="date" labelFunction="categoryLabel"/>
</mx:horizontalAxis>
<mx:horizontalAxisRenderers>
<mx:AxisRenderer axis="{cAxis}" labelRotation="{-25}"
canStagger="false" canDropLabels="true" />
</mx:horizontalAxisRenderers>
<mx:series>
<mx:ColumnSeries
xField="date"
yField="profit"
displayName="Profit"
fill="{sc1}"
stroke="{s1}"
/>
<mx:ColumnSeries
xField="date"
yField="expenses"
displayName="Expenses"
fill="{sc2}"
stroke="{s2}"
/>
</mx:series>
<mx:verticalAxis>
<mx:LinearAxis id="lAxis"/>
</mx:verticalAxis>
</mx:ColumnChart>
</mx:HBox>
</mx:Panel>
</s:Application>
I created a datagrid and also created some text box and a submit button outside the datagrid.. if we entered some data's into the text box and then click the submit button the data's are stored into the datagrid.. i want to export these data from the data grid is export into excel.How it possiple?How can i create a excel sheet and how it connect with my datagrid?
My code is given below
<?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" creationComplete="application1_creationCompleteHandler(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.as3xls.xls.Sheet;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.effects.easing.Exponential;
import mx.events.FlexEvent;
[Bindable]
public var dgItems_client:ArrayCollection = new ArrayCollection();
public var dgItems_admin:ArrayCollection = new ArrayCollection();
public var temp_client:Object = new Object();
public var temp_admin:Object = new Object();
private var fileRef:FileReference=new FileReference;
private var sheet:Sheet;
// public var imagegrid:Image;
private function tabChange():void
{
errorAdmin.visible=false;
errorClient.visible=false;
if(gh.selectedChild.name=='clientTab')
{
details.dataProvider=dgItems_client;
arrayName.headerText="Client_Name";
}
else
{
details.dataProvider=dgItems_admin;
arrayName.headerText="Admin_Name";
}
}
private function submitClick():void
{
if(name_client.text!="" && address_client.text!="" && phone_client.text!="")
{
temp_client = ({Name:name_client.text, Address:address_client.text,Phone_Number:phone_client.text});
dgItems_client.addItem(temp_client);
name_client.text="";
address_client.text="";
phone_client.text="";
clientClick();
errorClient.visible=false;
}
else
{
errorClient.visible=true;
}
if(name_admin.text!=""&&address_admin.text!=""&&phone_admin.text!="")
{
temp_admin = ({Name:name_admin.text, Address:address_admin.text,Phone_Number:phone_admin.text});
dgItems_admin.addItem(temp_admin);
name_admin.text="";
address_admin.text="";
phone_admin.text="";
errorAdmin.visible=false;
}
else
{
errorAdmin.visible=true;
}
}
private function clientClick():void
{
details.dataProvider=dgItems_client;
arrayName.headerText="Client_Name";
}
private function adminClick():void
{
details.dataProvider=dgItems_admin;
arrayName.headerText="Admin_Name";
}
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
fileRef.addEventListener(Event.SELECT,fileSelected);
}
private function fileSelected():void
{
}
private function executeExport():void
{
sheet=new Sheet;
// var dataProviderCollection:ArrayCollection;
var rowCount:int=details.columnsLength;
Alert.show(rowCount.toString());
}
]]>
</fx:Script>
<mx:TabNavigator x="27" y="11" width="455" height="376" id="gh" change="tabChange()" backgroundColor="#A4B6E9">
<s:NavigatorContent width="100%" height="100%" label="Client" id="clientTab">
<s:Label x="10" y="30" width="52" height="25" text="Name:"/>
<s:Label x="10" y="127" width="52" height="28" text="Address:"/>
<s:TextInput id="name_client" x="69" y="18" width="188" height="37" restrict="a-zA-Z"/>
<s:TextArea id="address_client" x="70" y="70" height="126"/>
<s:Label x="10" y="230" width="84" height="32" text="Phone:"/>
<s:TextInput id="phone_client" x="70" y="218" width="188" height="30" restrict="0-9" maxChars="10"/>
<s:Button x="100" y="291" height="28" label="Submit" click="submitClick()"/>
<s:Label id="errorClient" x="59" y="270" width="171" height="27" text="please fill the blank fields" color="red" visible="false"/>
</s:NavigatorContent>
<s:NavigatorContent width="100%" height="100%" label="Admin" id="adminTab" >
<s:Label x="23" y="48" width="52" height="25" text="Name:"/>
<s:Label x="26" y="148" width="52" height="28" text="Address:"/>
<s:TextInput id="name_admin" x="105" y="33" width="188" height="37"/>
<s:TextArea id="address_admin" x="105" y="93" height="126"/>
<s:Label x="26" y="257" width="84" height="32" text="Phone:"/>
<s:TextInput id="phone_admin" x="104" y="246" width="188" height="30" restrict="0-9" maxChars="10"/>
<s:Button x="137" y="305" height="28" label="Submit" click="submitClick()"/>
<s:Label id="errorAdmin" x="100" y="286" width="171" height="17" color="red" fontSize="14"
text="please fill the blank fields" visible="false"/>
<s:Button x="335" y="60" height="34" label="Admin Details" click="adminClick()"/>
<s:Button x="335" y="180" height="34" label="Client Details" click="clientClick()"/>
</s:NavigatorContent>
</mx:TabNavigator>
<s:TitleWindow x="521" y="84" width="377" height="234">
<s:DataGrid x="0" y="0" width="375" height="163" borderVisible="true" id="details">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="Name" id="arrayName"></s:GridColumn>
<s:GridColumn dataField="Address" headerText="Address"></s:GridColumn>
<s:GridColumn dataField="Phone_Number" headerText="Phone_Number"></s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
<s:Button x="139" y="167" height="28" label="Export" click="executeExport()"/>
</s:TitleWindow>
</s:Application>
ok...
You can try below code: -
<?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:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.as3xls.xls.Sheet;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.effects.easing.Exponential;
import mx.events.FlexEvent;
[Bindable]
public var dgItems_client:ArrayCollection = new ArrayCollection();
public var dgItems_admin:ArrayCollection = new ArrayCollection();
public var temp_client:Object = new Object();
public var temp_admin:Object = new Object();
private function tabChange():void
{
errorAdmin.visible=false;
errorClient.visible=false;
if(gh.selectedChild.name=='clientTab')
{
details.dataProvider=dgItems_client;
arrayName.headerText="Client_Name";
}
else
{
details.dataProvider=dgItems_admin;
arrayName.headerText="Admin_Name";
}
}
private function submitClick():void
{
if(gh.selectedIndex == 0)
{
if(name_client.text!="" && address_client.text!="" && phone_client.text!="")
{
temp_client = ({Name:name_client.text, Address:address_client.text,Phone_Number:phone_client.text});
dgItems_client.addItem(temp_client);
name_client.text="";
address_client.text="";
phone_client.text="";
clientClick();
errorClient.visible=false;
}
else
{
errorClient.visible=true;
}
}else
{
if(name_admin.text!="" && address_admin.text!="" && phone_admin.text!="")
{
temp_admin = ({Name:name_admin.text, Address:address_admin.text,Phone_Number:phone_admin.text});
dgItems_admin.addItem(temp_admin);
name_admin.text="";
address_admin.text="";
phone_admin.text="";
errorAdmin.visible=false;
}
else
{
errorAdmin.visible=true;
}
}
}
private function clientClick():void
{
details.dataProvider=dgItems_client;
arrayName.headerText="Client_Name";
}
private function adminClick():void
{
details.dataProvider=dgItems_admin;
arrayName.headerText="Admin_Name";
}
private function executeExport():void
{
ExcelExporterUtil.dataGridExporter(this.details, "prueba_excel.xls");
}
]]>
</fx:Script>
<mx:TabNavigator x="27" y="11" width="455" height="376" id="gh" change="tabChange()" backgroundColor="#A4B6E9">
<s:NavigatorContent width="100%" height="100%" label="Client" id="clientTab">
<s:Label x="10" y="30" width="52" height="25" text="Name:"/>
<s:Label x="10" y="127" width="52" height="28" text="Address:"/>
<s:TextInput id="name_client" x="69" y="18" width="188" height="37" restrict="a-zA-Z"/>
<s:TextArea id="address_client" x="70" y="70" height="126"/>
<s:Label x="10" y="230" width="84" height="32" text="Phone:"/>
<s:TextInput id="phone_client" x="70" y="218" width="188" height="30" restrict="0-9" maxChars="10"/>
<s:Button x="100" y="291" height="28" label="Submit" click="submitClick()"/>
<s:Label id="errorClient" x="59" y="270" width="171" height="27" text="please fill the blank fields" color="red" visible="false"/>
</s:NavigatorContent>
<s:NavigatorContent width="100%" height="100%" label="Admin" id="adminTab" >
<s:Label x="23" y="48" width="52" height="25" text="Name:"/>
<s:Label x="26" y="148" width="52" height="28" text="Address:"/>
<s:TextInput id="name_admin" x="105" y="33" width="188" height="37"/>
<s:TextArea id="address_admin" x="105" y="93" height="126"/>
<s:Label x="26" y="257" width="84" height="32" text="Phone:"/>
<s:TextInput id="phone_admin" x="104" y="246" width="188" height="30" restrict="0-9" maxChars="10"/>
<s:Button x="137" y="305" height="28" label="Submit" click="submitClick()"/>
<s:Label id="errorAdmin" x="100" y="286" width="171" height="17" color="red" fontSize="14"
text="please fill the blank fields" visible="false"/>
<s:Button x="335" y="60" height="34" label="Admin Details" click="adminClick()"/>
<s:Button x="335" y="180" height="34" label="Client Details" click="clientClick()"/>
</s:NavigatorContent>
</mx:TabNavigator>
<s:TitleWindow x="521" y="84" width="377" height="234">
<mx:DataGrid x="0" y="0" width="375" height="163" borderVisible="true" id="details">
<mx:columns>
<mx:DataGridColumn dataField="Name" id="arrayName"></mx:DataGridColumn>
<mx:DataGridColumn dataField="Address" headerText="Address"></mx:DataGridColumn>
<mx:DataGridColumn dataField="Phone_Number" headerText="Phone_Number"></mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<s:Button x="139" y="167" height="28" label="Export" click="executeExport()"/>
</s:TitleWindow>
</s:Application>
ExcelExporterUtil.as
package
{
import com.as3xls.xls.ExcelFile;
import com.as3xls.xls.Sheet;
import flash.errors.IllegalOperationError;
import flash.net.FileReference;
import flash.utils.ByteArray;
import mx.collections.ArrayCollection;
import mx.collections.ICollectionView;
import mx.collections.IViewCursor;
import mx.collections.XMLListCollection;
import mx.controls.DataGrid;
public class ExcelExporterUtil
{
public function ExcelExporterUtil()
{
throw new IllegalOperationError("Class \"ExcelExporterUtil\" is static. You can't instance this");
}
static public function dataGridExporter(dg:DataGrid, defaultName:String):void
{
if (dg == null || dg.dataProvider == null || defaultName == null || defaultName == "")
return;
var cols:Number = 0;
var colsValues:Array = [];
var cantCols:Number = dg.columnCount;
var fieldT:String;
var headerT:String;
// armo el listado de headers y variables para cada columna
for ( ; cols < cantCols; cols++)
{
headerT = (dg.columns[cols] as Object).headerText
fieldT = (dg.columns[cols] as Object).dataField;
if ( fieldT == null || fieldT == "" || headerT == null || headerT == "")
continue;
colsValues.push({
header:headerT,
value:fieldT
});
}
if ( colsValues.length == 0 )
return;
ExcelExporterUtil.export(dg.dataProvider, colsValues, defaultName);
}
static public function chartExporter(chart:ByteArray, defautlName:String):void
{
if(chart)
{
var sheet:Sheet = new Sheet();
sheet.resize(1, 1);
sheet.setCell(0, 0, "Chart Data");
sheet.setCell(0,0,chart);
var xls:ExcelFile = new ExcelFile();
xls.sheets.addItem(sheet);
var bytes:ByteArray = xls.saveToByteArray();
var fr:FileReference = new FileReference();
fr.save(bytes, defautlName);
}
}
static public function export(obj:Object, colsValues:Array, defautlName:String):void
{
var _dp:ICollectionView = ExcelExporterUtil.getDataProviderCollection(obj);
if ( _dp == null )
return;
var rows:Number = 0;
var cols:Number = 0;
var cantCols:Number = colsValues.length;
var sheet:Sheet = new Sheet();
sheet.resize(_dp.length, colsValues.length);
for ( ; cols < cantCols; cols++)
{
sheet.setCell(rows, cols, colsValues[cols].header);
}
cols = 0;
rows++;
var cursor:IViewCursor = _dp.createCursor();
while ( !cursor.afterLast )
{
for (cols = 0 ; cols < cantCols; cols++)
{
if ( (cursor.current as Object).hasOwnProperty(colsValues[cols].value) )
sheet.setCell(rows, cols, (cursor.current as Object));
}
rows++;
cursor.moveNext();
}
var xls:ExcelFile = new ExcelFile();
xls.sheets.addItem(sheet);
var bytes:ByteArray = xls.saveToByteArray();
var fr:FileReference = new FileReference();
fr.save(bytes, defautlName);
}
static private function getDataProviderCollection(obj:Object):ICollectionView
{
if ( (obj is Number && isNaN(obj as Number)) || (!(obj is Number) && obj == null))
{
return null;
}
else if ( obj is ICollectionView )
{
return obj as ICollectionView;
}
else if ( obj is Array )
{
return new ArrayCollection(obj as Array);
}
else if ( obj is XMLList )
{
return new XMLListCollection(obj as XMLList);
}
else if ( obj is XML )
{
var col:XMLListCollection = new XMLListCollection();
col.addItem(obj);
return col;
}
else if ( obj is Object )
{
return new ArrayCollection([obj]);
}
else
{
return null;
}
}
}
}
Hope may help you....
Note: - i am using ExcelExporterUtil.as from one of the post.. not created by me..
Or Other way, can refer below post: -
http://cookbooks.adobe.com/post_Import_Export_data_in_out_of_a_Datagrid_in_Flex-17223.html
I work with TileList to display image like a gallery.
At start, I activate only drag option.
<mx:TileList xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
columnWidth="120"
rowHeight="150"
paddingLeft="2"
paddingRight="2"
paddingTop="2"
paddingBottom="2"
itemRenderer="fr.ui.display._43Imagerie.TileUnit2"
doubleClickEnabled="true"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"
verticalScrollPolicy="on"
>
Now I try to add multiple selection possibility.
ItemRenderer is :
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
verticalScrollPolicy="off"
horizontalScrollPolicy="off"
width="120"
height="150"
borderVisible="false"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="onEvent()"
>
<mx:Script>
<![CDATA[
import fr.util.imageTransform;
import mx.controls.Image;
import mx.core.UIComponent;
import mx.events.DragEvent;
import mx.managers.DragManager;
import org.osmf.utils.URL;
import spark.effects.Rotate;
[Bindable]
[Embed(source="icon/imagerie/rotate.png")]
private var rotationArrowClass:Class;
private var _file:File;
private var _selected:Boolean;
private var _sauvBMD:BitmapData;
public var wasScaled:Boolean = false;
public var deleted:Boolean = false;
private var bgCenterX:Number;
private var bgCenterY:Number;
private var _dragDownPt:Point;
[Bindable]
public var angle:int = 0;
private var dragBitmapData : BitmapData;
private function onEvent():void
{
// iconCanvas.addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClick);
// double click gere ds wPlanchePhoto3
}
private function rotationImage(e:MouseEvent):void
{
var rot:Rotate = new Rotate();
rot.angleBy = 90;
rot.duration = 1000;
rot.autoCenterTransform = true;
rot.target = iconCanvas;
rot.play();
}
private function radiansToDegrees(radians:Number):Number {
var degrees:Number = radians * (180 / Math.PI);
return degrees;
}
private function degreesToRadians(degrees:Number):Number {
var radians:Number = degrees * (Math.PI / 180);
return radians;
}
public function set image(im:BitmapData):void
{
this._sauvBMD=im;
}
public function get image() :BitmapData
{
return this._sauvBMD;
}
protected function iconCanvas_mouseDownHandler(event:MouseEvent):void
{
// on enregistre la point de départ
_dragDownPt = new Point(mouseX,mouseY);
// puis on écoute l'éventuel déplacement de la souris
this.addEventListener(MouseEvent.MOUSE_MOVE,_onMouseMoveDuringDrag);
}
private function _onMouseMoveDuringDrag(evt:MouseEvent):void {
// astuce pour s'assurer que la souris a vraiment bougee volontairement
if(Math.abs(_dragDownPt.x - mouseX) <= 2 && Math.abs(_dragDownPt.y - mouseY) <= 2)
return;
else{
dragBitmapData = new BitmapData(iconCanvas.width, iconCanvas.height,true, 1);
dragBitmapData.draw(iconCanvas);
var transfert:Clipboard = new Clipboard();
transfert.setData(ClipboardFormats.BITMAP_FORMAT,Bitmap(iconCanvas.content).bitmapData);
// only allow the file to be copied
var dragOptions:NativeDragOptions = new NativeDragOptions();
dragOptions.allowMove=false;
dragOptions.allowCopy = true;
dragOptions.allowLink = false;
// begin the drag
NativeDragManager.doDrag(this, transfert, dragBitmapData, null, dragOptions);
}
// dispatch de l'event depuis le parent pour pouvoir écouter cet event dans l'application
}
]]>
</mx:Script>
<s:BorderContainer
id="bcImage"
width="120"
height="99%"
borderVisible="true"
borderColor="#FFFFFF"
borderWeight="1"
cornerRadius="6"
backgroundAlpha=".4"
backgroundColor="#5f5f5f"
>
<mx:Canvas id="cvsImage" width="100%">
<mx:SWFLoader id="rotationArrow" source="{rotationArrowClass}" height="18" width="18" x="3" y="3" visible="true" click="rotationImage(event);" alpha=".5"/>
<s:Label x="23" y="3" width="82" fontSize="11" fontWeight="normal" text="{data.imDate}"
textAlign="right" color="#000000"/>
<mx:Image id="iconCanvas" x="10" y="20" width="99" height="99" horizontalAlign="center"
maintainAspectRatio="true" scaleContent="true"
source="{data.imURL}"
verticalAlign="middle" mouseDown="iconCanvas_mouseDownHandler(event)"
>
</mx:Image>
</mx:Canvas>
<s:VGroup width="100%" y="124" height="25" bottom="1" left="3" right="3" paddingBottom="0" paddingTop="4" gap="0">
<s:Label text="{data.imType}" height="50%" fontSize="10" paddingBottom="1"
fontWeight="normal" width="99%" textAlign="center" color="#000000"/>
<s:Label text="{data.imStade}" fontSize="10" textAlign="center" paddingTop="1"
fontWeight="normal" width="99%" color="#000000"/>
</s:VGroup>
</s:BorderContainer>
If this option is true (allowMultipleSelection), drag stop to work, do you know why?
Thanks for helping.
Adding allowMultipleSelection="true" worked just fine for me. I am running on a Mac with latest version of Flash Player. It seemed a bit flaky at first but after refreshing the page it worked just fine. Only thing I didn't have in my project was your data provider and item renderer. I really doubt your item renderer would cause an issue unless you are doing something crazy in there. Check to see if you have the latest Flash Player.
I created a flex application that snapshot a picture of the webcam. Im trying now to save every snapshop and display it directly when the image has been capture. But I cant seems to understand how to.
I want the images to be display in the Thumbnail box.
Any help ? or any sites I can found some help on ?
This is what I have for the moment
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top"
horizontalAlign="center" paddingTop="0" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.UIComponent;
private function videoDisplay_creationComplete() : void
{
var camera:Camera = Camera.getCamera();
if (camera)
{
videoDisplay.attachCamera(camera);
}
else
{
Alert.show("Oops, we can't find your camera.");
}
}
private function capture_click() : void
{
var snap:BitmapData = new BitmapData(320, 240, true);
var snapBmp:Bitmap = new Bitmap(snap);
snapBmp.width = 320;
snapBmp.height = 240;
if(snapshotHolder.numChildren > 0)
snapshotHolder.removeChildAt(0);
snapshotHolder.addChild(snapBmp);
snap.draw(videoDisplay);
}
]]>
</mx:Script>
<mx:HBox>
<mx:Panel title="Video">
<mx:VideoDisplay id="videoDisplay" creationComplete="videoDisplay_creationComplete();" width="320" height="240" />
</mx:Panel>
<mx:Panel title="Snapshot">
<mx:UIComponent id="snapshotHolder" width="320" height="240" />
</mx:Panel>
</mx:HBox>
<mx:HBox>
<mx:Button label="reload camera" click="videoDisplay_creationComplete();"/>
<mx:Button label="capture" click="capture_click();"/>
</mx:HBox>
<mx:HBox>
<mx:Panel title="Thumbnails">
<mx:UIComponent id="snapshotHolderTN" width="128" height="96" />
</mx:Panel>
</mx:HBox>
</mx:Application>
Pls try with this when u click for image snaps.
var bmp:BitmapData = new BitmapData(videodisplay.width,videodisplay.height);
bmp.draw(drawArea);
var jpgEncode:JPEGEncoder = new JPEGEncoder(50);
var imageByte:ByteArray = jpgEncode.encode(bmp);
var fileRef:FileReference = new FileReference;
fileRef.save(imageByte);