Export datagrid to excel - actionscript-3

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

Related

How can I stop audio from playing from a video file?

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>

Flex 4 Spark List Itemrender

Here is my itemRenderer:
<?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"
width="100%" height="40"
click="adCanvas.selected=data.object;" mouseDown="adCanvas.selected=data.object;"
creationComplete="init()" initialize="trace('initializing')" activate="checkActions()" dataChange="checkActions()" render="checkActions()">
<fx:Script>
<![CDATA[
import adBuilder.*;
import components.AdCanvas;
import events.AdLoadEvent;
import flash.display.Bitmap;
import flash.events.MouseEvent;
import flash.utils.describeType;
import interfaces.IAdObject;
import mx.core.FlexGlobals;
import mx.core.UIComponent;
import mx.events.CollectionEvent;
import mx.utils.*;
[Bindable] private var desc:String;
private var adCanvas:AdCanvas;
private var adBuilder:AdBuilder;
[Bindable]private var myvis:Boolean=false;
private const MAX_NAME_LENGTH:Number = 19;
private function init():void {
trace("!!!!!!!!!!!!!!!!!!!!! LAYER RENDERER !!!!!!!!!!!!!!!!!!!!!");
if (!data) data = {};
if (data.hasOwnProperty("first")) {
toggleEnabled(FlexGlobals.topLevelApplication.btnUp);
}
if (data.hasOwnProperty("last")) {
toggleEnabled(FlexGlobals.topLevelApplication.btnDown);
}
adCanvas = data.adCanvas;
if(IAdObject(data.object as IAdObject)){
if(IAdObject(data.object).animationObjects){
IAdObject(data.object).animationObjects.addEventListener(CollectionEvent.COLLECTION_CHANGE, checkActions);
checkActions();
}
}
iconType.source = findSource();
}
private function checkActions(e:Event=null):void{
try{
if(data){
if(IAdObject(data.object as IAdObject)){
if(IAdObject(data.object as IAdObject).animationObjects){
if(data.object.animationObjects.length>0){
this.myvis=true;
}else{
this.myvis=false;
}
}
}
}
iconType.source = findSource();
}catch(error:Error){
trace("LayerRenderer.mxml - checkActions(): " + error.message);
}
}
private function toggleEnabled(obj:UIComponent):void {
if (data.hasOwnProperty("first")) {
obj.useHandCursor = false;
obj.enabled = false;
obj.alpha = 0.5;
} else {
obj.useHandCursor = true;
obj.enabled = true;
obj.alpha = 1;
}
iconType.source = findSource();
}
private function hideLayers():void{
//dispatchEvent(new Event("Layer_Visible"));
trace("CLICKED EYE");
FlexGlobals.topLevelApplication.dispatchEvent(new Event('Layer_Visible'));
if (hideLayer.alpha == 1){
hideLayer.alpha = .5;
}
else if (hideLayer.alpha == .5){
hideLayer.alpha = 1;
}
//trace("parameters are " + ObjectUtil.toString(data));
}
private function findSource():*{
if (data){
//iconType.source = "";
if (data.type == "Image"){
//trace("data.name: " + data.name);
//trace("data.bitmapinfo: " + data.bitmapinfo);
return new Bitmap(data.bitmapinfo);
}
if (data.type == "Text"){
return("assets/images/Text2.png");
}
if (data.type == "Application"){
return
//return("assets/images/App.png");
}
if (data.type == "Button"){
return("assets/images/Button.png");
}
if (data.type == "Shape"){
return("assets/images/shape.png");
}
if (data.type == "SWF"){
return("assets/images/SWF.png");
}
else{
return "assets/images/placeholder.png";
}
}
else {
return "assets/images/placeholder.png";
}
}
private function truncateName(nameStr:String):String
{
var returnVal:String = (nameStr.indexOf(".") > -1) ? nameStr.substr(0, nameStr.indexOf(".")) : nameStr;
var extension:String = (nameStr.indexOf(".") > -1) ? nameStr.substr(nameStr.indexOf("."),nameStr.length) : "";
//trace("nameStr: " + nameStr);
//trace("extension: " + extension);
if (returnVal.length > MAX_NAME_LENGTH){
returnVal = returnVal.substr(0,MAX_NAME_LENGTH) + "...";
}/*else{
returnVal += extension;
}*/
return returnVal;
}
]]>
</fx:Script>
<s:Group id="layerGroup" width="100%" height="100%" top="10" left="5" bottom="10" right="10">
<s:HGroup left="0" verticalAlign="middle" width="100%">
<s:HGroup paddingBottom="40" paddingRight="10">
<mx:Image id="iconType" smoothBitmapContent="true" scaleContent="true" source="" height="20" width="20"/>
</s:HGroup>
<s:HGroup width="100%">
<s:Label toolTip="{data.name}" text="{truncateName(data.name)}" id="labelText" height="50" top="5" width="100%" maxDisplayedLines="1" left="0" color="#101010"/>
<s:Label toolTip="" text="{Math.ceil(data.fileSize/1000)+' K'}" textAlign="right" id="sizeText" height="50" top="5" width="70" maxDisplayedLines="1" left="0" color="#101010"/>
</s:HGroup>
<s:HGroup paddingBottom="40">
<mx:Image horizontalAlign="right" bottom="10" alpha="1" right="2" id="hideLayer" verticalAlign="middle" source="assets/images/visible.png" click="hideLayers()" useHandCursor="true"/>
<mx:Image id="actLabel" includeInLayout="false" visible="{this.myvis}" source="assets/images/star.png" />
</s:HGroup>
</s:HGroup>
</s:Group>
</s:ItemRenderer>
Here is the class that uses said renderer:
<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
left="5" top="10" bottom="0"
creationComplete="init();" rollOver="rolledOver(event)" rollOut="rolledOut(event)"
backgroundColor="#F0F0F0" backgroundAlpha="1" borderAlpha="0" borderColor="#3a3a3a" width="100%" height="60" currentState="out">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:states>
<s:State name="over"/>
<s:State name="out" />
</s:states>
<fx:Script>
<![CDATA[
import components.*;
import components.AdCanvas;
import events.AdCanvasObjectEvent;
import flash.system.LoaderContext;
import mx.collections.ArrayCollection;
import mx.controls.Image;
import mx.core.Application;
import mx.core.DragSource;
import mx.core.FlexGlobals;
import mx.core.IUIComponent;
import mx.core.UIComponent;
import mx.events.DragEvent;
import mx.graphics.ImageSnapshot;
import mx.managers.DragManager;
import spark.components.Group;
import spark.layouts.*;
[Bindable]
private var _data: Object;
[Bindable]
private var context:LoaderContext;
[Bindable]
public var canvas: AdCanvas;
[Bindable]
public var index: int;
[Bindable]
public var maxPreviewWidth: int;
[Bindable]
public var maxPreviewHeight: int;
[Bindable]
public var isSelected: Boolean = false;
[Bindable]
private var adRect:Rectangle;
[Bindable]
private var ad:BitmapData;
[Bindable]
public var layerData:ArrayCollection = new ArrayCollection();
[Bindable]
private var application:Object = FlexGlobals.topLevelApplication;
//public var layerList:List;
private const MAX_HEIGHT:Number = 400;
private const MINIMUM_HEIGHT:Number = 60;
private var t:Timer;
private var t2:Timer;
private var t3:Timer;
[Bindable]private var siblings:Array = new Array();
/**
* Initialize the preview item
*/
public function init(obj: Object = null): void {
//layersList.data = FlexGlobals.topLevelApplication.getLayerList();
//trace("Layer data " + layersList.data);
canvas.screenPreview = this;
context = new LoaderContext(false);
FlexGlobals.topLevelApplication.addEventListener(AdCanvasObjectEvent.UPDATED, updateThumbnail);
FlexGlobals.topLevelApplication.addEventListener(AdCanvasObjectEvent.ADDED, updateThumbnail);
FlexGlobals.topLevelApplication.addEventListener(AdCanvasObjectEvent.DELETED, updateThumbnail);
FlexGlobals.topLevelApplication.addEventListener(AdCanvasObjectEvent.SELECTED_SINGLE, updateThumbnail);
FlexGlobals.topLevelApplication.addEventListener(AdCanvasObjectEvent.SELECTED_MULTIPLE, updateThumbnail);
FlexGlobals.topLevelApplication.addEventListener(AdCanvasObjectEvent.DESELECT, updateThumbnail);
FlexGlobals.topLevelApplication.addEventListener("updateThumbnail", updateThumbnail);
// This is to prevent the security error when there is a loaded swf trying to be accessed for bitmap
Security.loadPolicyFile(FlexGlobals.topLevelApplication.parameters.mediaUrl+"../crossdomain.xml");*/
//if(root.loaderInfo.url.indexOf('file://')==-1)img.loaderContext = new LoaderContext(true, ApplicationDomain.currentDomain, SecurityDomain.currentDomain);
canvas.updatePreview();
buildThumb();
titleBar.addEventListener(MouseEvent.CLICK, mouseClick);
(adCanvas.isDeletable || adCanvas.isDeletable == "true") ? screenDelete.addEventListener(MouseEvent.CLICK, mouseClick) : null;
//layersList.addEventListener(DragEvent.DRAG_ENTER, handleDragEnter);
//layersList.addEventListener(DragEvent.DRAG_DROP, handleDragDrop);
//layersList.addEventListener(DragEvent.DRAG_START, handleDragStart);
this.addEventListener(DragEvent.DRAG_ENTER, handleDragEnter);
this.addEventListener(DragEvent.DRAG_DROP, handleDragScreenDrop);
//setHeight();
//setYPos();
}
private function handleDragStart(event:DragEvent):void{
try{
var obj:Object = (event.dragInitiator as List).selectedItem;
canvas.selected = obj["object"];
}catch (error:Error){
trace("ERROR: ScreenPreview.mxml - handleDragStart() : " + error.message);
}
}
private function handleDragEnter(event:DragEvent):void {
trace("event.dragInitiator: " + event.dragInitiator);
if( event.dragInitiator is List){
DragManager.acceptDragDrop(this);
DragManager.showFeedback(DragManager.MOVE);
layersList.dropEnabled = true;
}else{
layersList.dropEnabled = false;
}
}
private function handleDragDrop(event:DragEvent):void {
t = new Timer(500);
t.addEventListener(TimerEvent.TIMER, checkLayerData);
t.start();
}
private function handleDragScreenDrop(event:DragEvent):void {
/*trace("\n");
trace("TEEEEE HEEEEEE");
trace("event.target: " + event.target);
trace("event.currentTarge: " + event.currentTarget);
trace("this: " + this);
trace("event.dragInitiator: " + (event.dragInitiator as List).selectedItem);
trace("event.draggedItem: " + event.draggedItem);
trace("event.dragSource: " + event.dragSource);
*/
try
{
var obj:Object = (event.dragInitiator as List).selectedItem;
var clone:UIComponent = obj["element"].clone();
/*for( var i:* in obj)
{
trace( "obj["+i+"]: " + obj[i]);
}
trace("obj: " + obj);
*/
this.canvas.addObjectToCanvas(clone);
obj["adCanvas"].removeScreenElement(obj);
}catch(error:Error){
trace("ERROR: ScreenPreview - handleDragDrop() : " + error.message);
}
//trace("\n");
}
private function checkLayerData(e:TimerEvent):void
{
t.stop();
t = null;
adCanvas.updateItemIndex();
}
public function setSizeText(val:Number):void
{
sizeText.text = (Math.ceil(val/1000) + " K");
if (isSelected)
{
t3 = new Timer(100);
t3.addEventListener(TimerEvent.TIMER, delayResize);
t3.start();
}
}
/**
* Update the bitmap data for the screen when something has changed.
*/
public function updateThumbnail(ev: AdCanvasObjectEvent = null): void {
try{
canvas.gridOff();
var adRect:Rectangle = canvas.adBox.getBounds(canvas);
var snapshot: BitmapData = ImageSnapshot.captureBitmapData((canvas as IBitmapDrawable));
var ad:BitmapData = new BitmapData(adRect.width, adRect.height);
ad.copyPixels(snapshot, adRect, new Point());
img.source = new Bitmap(ad);
canvas.gridOn();
}catch(e:Error){
trace(e+"System can't convert external swf files to bitmap.");
canvas.gridOn();
}
}
/**
* Controls visuals for when the button is selected.
*/
public function set selected(state: Boolean): void
{
isSelected = state;
trace("MY STATE IS: " + state);
if (isSelected)
{
layersList.includeInLayout=true;
stroke.color=0x878787;
strokeColor.color=0x878787;
bg.color = 0x979fa7;
layersList.visible = true;
//layersList.percentHeight = 100;
screenSettings.visible = true;
(adCanvas.isDeletable || adCanvas.isDeletable == "true") ? screenDelete.visible = true : screenDelete.visible = false;
//percentHeight=100;
siblings.splice(0,siblings.length);
siblings = new Array();
try
{
for(var i:int=0; i < Group(parent).numChildren; i++)
{
siblings.push(Group(parent).getElementAt(i));
}
}
catch (e:Error) {}
t2 = new Timer(100);
t2.addEventListener(TimerEvent.TIMER, delayResize);
t2.start();
}
else
{
stroke.color=0x3C3C3C;
strokeColor.color=0x3C3C3C;
bg.color = 0x636B73;
currentState="out";
layersList.includeInLayout=false;
}
}
private function delayResize(evt:TimerEvent):void{
if(t2){
t2.stop();
t2.removeEventListener(TimerEvent.TIMER, delayResize);
t2 = null;
}
if(t3){
t3.stop();
t3.removeEventListener(TimerEvent.TIMER, delayResize);
t3 = null;
}
setHeight();
setYPos();
}
public function setYPos():void
{
for(var i:int = 0; i < siblings.length; i++)
{
if(i>0)
{
siblings[i].y = ( siblings[i-1].y + siblings[i-1].height);
}
if (siblings[i] != this){
ScreenPreview(siblings[i]).selected = false;
ScreenPreview(siblings[i]).checkLayer();
}
}
}
public function setHeight():void
{
for(var i:int = 0; i < siblings.length; i++)
{
if( siblings[i] == this )
{
if( (MINIMUM_HEIGHT + totLayersHeight()) > MAX_HEIGHT){
height = MAX_HEIGHT;
}else{
height = MINIMUM_HEIGHT + totLayersHeight();
}
}
trace("###################################################");
trace("ScreenPreview - canvas: " + canvas);
trace("ScreenPreview - canvas.href: " + canvas.href);
trace("ScreenPreview - canvas.click_label: " + canvas.click_label);
trace("###################################################");
FlexGlobals.topLevelApplication.setMouseActionsFromObject();
}
}
private function totLayersHeight():Number{
trace("this.layerData.length: " + this.layerData.length);
var val:Number = 0;
//multiply by 40 because that is the height of each layer item
if( this.layerData.length > 0) val = (this.layerData.length + 1) * 40;
return val;
}
public function checkLayer ():void{
screenSettings.visible = false;
screenDelete.visible = false;
layersList.visible = false;
//percentHeight=15;
height = 60;
}
/**
* Controls visuals for when the button is rolled over.
*/
private function rolledOver(e:Event):void
{
str.color=0xffc423;
bg.color=0xBAC2CA;
}
/**
* Controls visuals for when the button is rolledout.
*/
private function rolledOut(e:Event):void{
if(!isSelected){
bg.color=0x636B73;
/*g1.color=0xCBCBCB;
g2.color=0xD9D9D9;
str.color=0xCBCBCB;
lg.rotation=-90;*/
}else{
bg.color=0x979fa7;
/*g1.color=0xCBCBCB;
g2.color=0xCBCBCB;
str.color=0xCBCBCB;
lg.rotation=90*/
}
}
/**
* Set up the canvas and SWF sizes, as well as label, for the screen thumbnail.
*/
public function buildThumb():void{
adRect = new Rectangle(15, 15, canvas.adBox.width, canvas.adBox.height);
ad = new BitmapData(adRect.width + 100, adRect.height + 100, true, 0);
setImageSize();
labelText.text = "Screen "+canvas.index;//+": "+canvas.adWidth+"x"+canvas.adHeight;
updateThumbnail();
}
/**
* Get the scaled-down screen size.
*/
private function getScaledDimensions(targetHeight:int=100, targetWidth:int=100): Object {
var xScaleFactor: Number = (maxPreviewWidth > targetWidth) ? (targetWidth/maxPreviewWidth) : 1;
var yScaleFactor: Number = (maxPreviewHeight > targetHeight) ? (targetHeight/maxPreviewHeight) : 1;
var scaleFactor: Number = (xScaleFactor < yScaleFactor) ? xScaleFactor : yScaleFactor;
var dimensions: Object = {
width: Math.round(adRect.width * scaleFactor),
height: Math.round(adRect.width * scaleFactor)
}
return dimensions;
}
/**
* Change the the thumb size and position based on the ad size.
*/
private function setImageSize():void
{
var w:Number = adRect.width + 100;
var h:Number = adRect.height + 100;
var scaler:Number = (w>h)?40/w:27/h;
img.width = w*scaler;
img.height = h*scaler;
rolledOut(null);
imgBox.left = 10;
if (w > (h*2)){
imgBox.top=15;
}
if (h > (w*2)){
imgBox.top = 5;
}
}
private function mouseClick(e:MouseEvent):void
{
trace("did the click");
e.stopImmediatePropagation();
if( e.currentTarget == screenDelete)
{
trace("DISPATCH DELETE SCREEN");
dispatchEvent(new Event('delete_screen_click'));
}else{
trace("DISPATCH MOUSE CLICK");
dispatchEvent(new Event('mouse_click'));
FlexGlobals.topLevelApplication.dispatchEvent(new AdCanvasObjectEvent(AdCanvasObjectEvent.DESELECT));
}
//FlexGlobals.topLevelApplication.updateLayerScreens();
}
private function deleteThisScreen(e:MouseEvent):void
{
dispatchEvent(new Event('delete_screen_click'));
}
/**
* Getter and setter for adcanvas that we are using for the thumbnail
*/
public function set adCanvas(canv: AdCanvas): void {
canvas = canv;
index = canv.index;
}
public function get adCanvas(): AdCanvas {
return canvas;
}
/**
* Getter for checking if this button has been selected.
*/
public function get selected(): Boolean {
return isSelected;
}
private function settingsMenu():void{
FlexGlobals.topLevelApplication.dispatchEvent(new AdCanvasObjectEvent(AdCanvasObjectEvent.DESELECT));
FlexGlobals.topLevelApplication.openSettings();
}
]]>
</fx:Script>
<s:VGroup left="1" right="1" top="1" height="100%" width="100%" paddingBottom="5">
<s:VGroup id="titleBar" height="55" top="20" width="100%">
<s:HGroup top="5" left="5" height="100%" width="100%">
<s:Group width="55" height="50">
<s:Rect id="fill" left="5" right="0" top="0" bottom="0" radiusX="0">
<s:fill>
<s:SolidColor id="bg" color="0x979fa7"/>
</s:fill>
<s:stroke>
<s:SolidColorStroke id="stroke" color="0x3C3C3C" alpha="1"/>
</s:stroke>
</s:Rect>
<s:HGroup id="vg" height="50" width="100%" gap="0">
<s:Group height="15" top="2" width="100%">
<s:VGroup top="5" id="imgBox" width="15">
<mx:Image left="5" id="img" scaleContent="true" height="50" width="50" top="10" />
</s:VGroup>
</s:Group>
</s:HGroup>
<s:Rect left="1" right="1" top="1" bottom="1" radiusX="0" >
<s:stroke>
<s:SolidColorStroke id="str" color="0x979fa7" weight="2" alpha="0" />
</s:stroke>
</s:Rect>
</s:Group>
<s:Group left="0" top="0" height="60" width="100%">
<s:Rect top="0" left="5" right="0" bottom="0" bottomLeftRadiusX="0" bottomRightRadiusX="0">
<s:fill>
<s:SolidColor id="bg2" color="0xDCE4EC" alpha="0"/>
</s:fill>
<s:stroke>
<s:SolidColorStroke id="strokeColor" color="0x3C3C3C" alpha="0"/>
</s:stroke>
</s:Rect>
<s:HGroup verticalAlign="middle" top="15" width="100%">
<mx:Text id="labelText" text="" selectable="false" color="#3a3a3a" width="100%" fontSize="10" textAlign="center" />
<mx:Text id="sizeText" text="" selectable="false" color="#3a3a3a" width="100%" fontSize="10" textAlign="right" />
</s:HGroup>
</s:Group>
<s:Group>
<mx:Image source="assets/images/trashcan-delete.png" visible="false" toolTip="Delete This Screen" id="screenDelete" top="15" right="45" useHandCursor="true"/>
<mx:Image source="assets/images/cog.png" visible="false" toolTip="Edit Screen Settings" top="15" right="11" id="screenSettings" click="settingsMenu()" useHandCursor="true"/>
</s:Group>
</s:HGroup>
</s:VGroup>
<s:VGroup id="layerPanel" includeInLayout="true" paddingBottom="1" height="100%" width="100%">
<s:List creationComplete="{trace('TEEEEEEEEEEEEE HEEEEEEEEEEEEEEE')}"
id="layersList"
dragStart="{handleDragStart(event)}" dragEnter="{handleDragEnter(event)}" dragDrop="{handleDragDrop(event)}"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"
includeInLayout="true"
visible="true"
initialize="application.setUpLayers()"
dataProvider='{layerData}'
selectedIndex="{application.getLayerListIndex()}"
render='{layersList.selectedIndex=application.getLayerListIndex()}'
itemRenderer="renderers.LayerRenderer"
width="100%"
height="100%"
bottom="50"
alternatingItemColors="[#e2e2e2, #dedede]"
selectionColor="#787878"
rollOverColor="#949494"
borderVisible="false"
/>
</s:VGroup>
</s:VGroup>
</s:BorderContainer>
The problem I'm having is the itemRenderer never gets called. I put trace statements just to be sure and nothing. These two files once used mx:canvas and were converted. I've been beating my head against a wall for 2 days with this issue. Help is much appreciated.

Is there any way to synchronize flex application tool with browser forward and backward button

I have create an flex application tool which used BrowserManager class to synchronization between flex application tool and browser forward/backward button. It works fine in firefox but did not work properly in other browser(safari,IE,Chrome).
Code is as folow :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
historyManagementEnabled="false"
creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
import mx.effects.effectClasses.AddRemoveEffectTargetFilter;
import mx.events.BrowserChangeEvent;
import mx.managers.IBrowserManager;
import mx.managers.BrowserManager;
import mx.utils.URLUtil;
private var bm:IBrowserManager;
private function onCreationComplete() : void
{
bm = BrowserManager.getInstance(); //get an instance of the browserManager
bm.init(); //initialize the browser manager
updateContainers(); //set visible containers based on url parameters
bm.addEventListener( BrowserChangeEvent.BROWSER_URL_CHANGE, onURLChange ); //add event listeners to handle back/forward browser buttons
updateURL();
}
private function updateContainers():void
{
var o:Object = URLUtil.stringToObject(bm.fragment);
if ( !isNaN(o.selectedIndex) )
{
var newIndex : Number = o.selectedIndex;
if ( newIndex >= 0 && newIndex < tabNav.numChildren )
tabNav.selectedIndex = newIndex;
}
}
private function onURLChange( event:BrowserChangeEvent ):void
{
updateContainers();
}
private function updateURL():void
{
bm.setFragment( "selectedIndex=" + tabNav.selectedIndex );
}
]]>
</mx:Script>
<mx:TabNavigator
bottom="10"
top="10"
right="10"
left="10"
id="tabNav"
historyManagementEnabled="false"
>
<mx:Canvas label="Tab 0" show="updateURL()" >
<mx:Label text="Tab 0 Contents" />
</mx:Canvas>
<mx:Canvas label="Tab 1" show="updateURL()" >
<mx:Label text="Tab 1 Contents" />
</mx:Canvas>
<mx:Canvas label="Tab 2" show="updateURL()" >
<mx:Label text="Tab 2 Contents" />
</mx:Canvas>
</mx:TabNavigator>
</mx:Application>
Is there any solution for this problem...?
I have got an answer of mine own question. The code is as follow :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
historyManagementEnabled="false"
creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
import com.asual.swfaddress.SWFAddressEvent;
import com.asual.swfaddress.SWFAddress;
import mx.effects.effectClasses.AddRemoveEffectTargetFilter;
import mx.events.BrowserChangeEvent;
import mx.managers.IBrowserManager;
import mx.managers.BrowserManager;
import mx.utils.URLUtil;
import com.asual.swfaddress.*;
private var bm:IBrowserManager;
private function onCreationComplete() : void
{
SWFAddress.addEventListener(SWFAddressEvent.CHANGE, onChange);
}
private function onChange(e:SWFAddressEvent):void
{
if(e.value != "/")
SWFAddress.setTitle("Nail Designer " + e.value.substring(1));
else
SWFAddress.setTitle("Nail Designer - Tab1Selected ");
switch(e.value)
{
case "/Tab1Selected":
tabNav.selectedIndex = 0;
break;
case "/Tab2Selected":
tabNav.selectedIndex = 1;
break;
case "/Tab3Selected":
tabNav.selectedIndex = 2;
break;
case "/":
tabNav.selectedIndex = 0;
break;
}
}
public function onCanvas_Click():void
{
if(tabNav.selectedIndex == 0)
SWFAddress.setValue("Tab1Selected");
else if(tabNav.selectedIndex == 1)
SWFAddress.setValue("Tab2Selected");
else if(tabNav.selectedIndex == 2)
SWFAddress.setValue("Tab3Selected");
}
]]>
</mx:Script>
<mx:TabNavigator
bottom="10"
top="10"
right="10"
left="10"
id="tabNav"
historyManagementEnabled="false"
>
<mx:Canvas label="Tab 1" show="onCanvas_Click()" >
<mx:Label text="Tab 0 Contents" />
</mx:Canvas>
<mx:Canvas label="Tab 2" show="onCanvas_Click()" >
<mx:Label text="Tab 1 Contents" />
</mx:Canvas>
<mx:Canvas label="Tab 3" show="onCanvas_Click()" >
<mx:Label text="Tab 2 Contents" />
</mx:Canvas>
</mx:TabNavigator>
</mx:Application>
This code only run when you have swfaddress.js, swfobject.js file and SWFAddress.as,
SWFAddressEvent.as class. This files you can download fron link :
http://www.asual.com/swfaddress/

mx:TileList : Why drag doesn't works if allowMultipleSelection is activate

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.

mx:List itemrenderer acces value

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