我正在使用Flash Builder中的项目遇到问题。 以下是我的堆栈和代码示例。有人可以告诉我我做错了吗?
感谢您的时间。
- 堆叠 -
ReferenceError:错误#1069:在WOAPPv2上找不到属性页面4,并且没有默认值。 在WOAPPv2 / dragDropHandler()[/ Users / martinw / Documents / Adobe Flash Builder 4 / WOAPPv2 / src / WOAPPv2.mxml:165] 在flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() 在mx.core :: UIComponent / dispatchEvent()[E:\ dev \ 4.x \ frameworks \ projects \ framework \ src \ mx \ core \ UIComponent.as:12528] 在mx.managers.dragClasses :: DragProxy / _dispatchDragEvent()[E:\ dev \ 4.x \ frameworks \ projects \ framework \ src \ mx \ managers \ dragClasses \ DragProxy.as:374] 在mx.managers.dragClasses :: DragProxy / mouseUpHandler()[E:\ dev \ 4.x \ frameworks \ projects \ framework \ src \ mx \ managers \ dragClasses \ DragProxy.as:599]
- 代码示例 - 这有效吗
import mx.core.DragSource;
import mx.events.DragEvent;
import mx.managers.DragManager;
private function initiateDrag(event:MouseEvent,value:String):void{
var dragInitiator:Image= event.currentTarget as Image;
var dragSource:DragSource = new DragSource();
dragSource.addData(value, 'value');
DragManager.doDrag(dragInitiator, dragSource, event);
}
private function dragEnterHandler(event:DragEvent):void {
var dropTarget:VBox =event.currentTarget as VBox;
if (event.dragSource.hasFormat('value')) {
DragManager.acceptDragDrop(dropTarget);
}
}
private function dragDropHandler(event:DragEvent):void {
var pageName:String = event.currentTarget.name as String;
var value:String = event.dragSource.dataForFormat('value') as String;
this[pageName].source = "assets/big/"+value;
}
<s>
<s:HGroup id="hGr"
requestedColumnCount="2"
variableColumnWidth="false"
columnWidth="475"
height="450"
gap="100"
clipAndEnableScrolling="true" paddingLeft="10" paddingRight="10">
<mx:VBox name="page1"
backgroundColor="#EFEFF0"
verticalScrollPolicy="off"
horizontalScrollPolicy="off"
horizontalAlign="center" verticalAlign="middle"
dragEnter="dragEnterHandler(event)"
dragDrop="dragDropHandler(event)"
width="475"
x="0">
<mx:Image id="page1" showBusyCursor="true" width="713" height="692" scaleContent="true" maintainAspectRatio="true" minWidth="713" minHeight="692" scaleX="1" scaleY="1" horizontalAlign="center" verticalAlign="top"/>
</mx:VBox>
</s:HGroup>
它打破如果我这样做,通过在运行时创建容器和图像
<script>
private function initVars():void {
createSpreads();
}
public function createSpreads():void {
var s:VBox = new VBox();
s.name ="page4";
s.setStyle("backgroundColor","#fe0000");
s.verticalScrollPolicy="off";
s.horizontalScrollPolicy="off";
s.setStyle("horizontalAlign","center");
s.setStyle("verticalAlign","middle");
s.addEventListener(DragEvent.DRAG_ENTER, dragEnterHandler);
s.addEventListener(DragEvent.DRAG_DROP, dragDropHandler);
s.width= 475;
s.setStyle("x","0");
hGr.addElement(s);
hGrCol4.text = "Vboxname: "+s.name+"VboxID: "+s.id;
var page3:Image = new Image();
page3.id ="page4";
page3.showBusyCursor = true;
page3.width = 713;
page3.height = 692
page3.scaleContent = true;
page3.maintainAspectRatio = true;
page3.minWidth = 713;
page3.minHeight = 692;
page3.scaleX = 1;
page3.scaleY = 1;
page3.source = "assets/big/IMG_7112.jpg";
page3.setStyle("backgroundColor","#ffffff");
page3.setStyle("horizontalAlign","center");
page3.setStyle("verticalAlign","top");
s.addElement(page3);
hGrCol3.text = "Imagename: "+page3.name+"ImageID: "+page3.id;
}
import mx.core.DragSource;
import mx.events.DragEvent;
import mx.managers.DragManager;
private function initiateDrag(event:MouseEvent,value:String):void{
var dragInitiator:Image= event.currentTarget as Image;
var dragSource:DragSource = new DragSource();
dragSource.addData(value, 'value');
DragManager.doDrag(dragInitiator, dragSource, event);
}
private function dragEnterHandler(event:DragEvent):void {
var dropTarget:VBox =event.currentTarget as VBox;
if (event.dragSource.hasFormat('value')) {
DragManager.acceptDragDrop(dropTarget);
}
}
private function dragDropHandler(event:DragEvent):void {
var pageName:String = event.currentTarget.name as String;
var value:String = event.dragSource.dataForFormat('value') as String;
this[pageName].source = "assets/big/"+value;
}
</script>
<s>
<s:HGroup id="hGr"
requestedColumnCount="2"
variableColumnWidth="false"
columnWidth="475"
height="450"
gap="100"
clipAndEnableScrolling="true" paddingLeft="10" paddingRight="10">
</s:HGroup>
</s>
上面没有HGroup中的容器返回'在WOAPPv2上找不到的属性page4并且没有默认值' - 我的最终结果应该是这个
page4.source =“assets / big / imagename.jpg”;
我很难过。我正在重新思考它,可能只是创建vbox,然后设置触发器来创建图像并填充在sameDragDropHandler中。 想法?
以下是解决方案 - 再次 - 感谢alxx。现在我需要开始向其他人提供我的知识。
public function dragDropHandler(event:DragEvent):void {
// Retrieve the Image Name from Drop
var value:String = event.dragSource.dataForFormat('value') as String;
//
event.currentTarget.getChildAt(0).source = "assets/big/"+value;
}
答案 0 :(得分:0)
...继续在这里进行正确的格式化 问题专栏:
var value:String = event.dragSource.dataForFormat('value') as String;
this[pageName].source = "assets/big/"+value;
我的目标是添加vbox和 与之共享名称的图像子项 一个id并使用该事件来抓住 currenttarget名称是图像 控制
不确定我是否理解正确。如果event.currentTarget是您需要的Image,您可以将其强制转换为Image。或者您需要在某处找到另一个图像(一个在Repeater中生成)?
<强>更新强>
“我正在尝试使用VBox的名称作为字符串,用于点符号来引用其中的图像”
DisplayObjects的名称只是标签,而不是引用。如果您认为可以使用JS DOM中的名称遍历对象层次结构,那么不,它在Flash中以其他方式完成。您可以使用event.currentTarget
将引用提供给VBox - 它的名称(String)更有用。您可以使用getChildAt在其中获取Image。