关于Flex4中的drag

     今天做控件之间的数据拖动时,始终要出现空指针错误,很郁闷,后来才发现,flex4和flex3的拖动有很大的不同,flex4中必须设定一个数据源,用来存放值,如果没有设置,数据就不知道怎么保存。

 

 

-----------------------在flex3中这样就行了------------------

 

 

<?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">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
		<s:ArrayList id="data1">
			<fx:String>1</fx:String>
			<fx:String>2</fx:String>
			<fx:String>3</fx:String>
			<fx:String>4</fx:String>
		</s:ArrayList>
		
	</fx:Declarations>
	<mx:List x="92" y="82" width="200" dataProvider="{data1}" dragEnabled="true"/> 
	<mx:List x="442" y="82" width="200" dropEnabled="true"/>
</s:Application>

 

 

 

 

-----------------------但是flex4中会报空引用错误,加上数据源就好了------------------

 

 

<?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">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
		<s:ArrayList id="data1">
			<fx:String>1</fx:String>
			<fx:String>2</fx:String>
			<fx:String>3</fx:String>
			<fx:String>4</fx:String>
		</s:ArrayList>
		<s:ArrayList id="data2">
			<fx:String>1</fx:String>
		</s:ArrayList>
	</fx:Declarations>
	<s:List x="92" y="82" width="200" dataProvider="{data1}" dragEnabled="true"> </s:List>
	<s:List x="442" y="82" width="200" dropEnabled="true" dataProvider="{data2}"></s:List>
</s:Application>
 

你可能感兴趣的:(xml,Flex,Adobe)