Flex 动作脚本中的 setStyle backgroundImage 不起作用
我正在动态创建画布,并且我需要画布内的背景图像。画布在接受拖放时创建,但背景图像不显示。
画布的触发器是:
buttonNew.addEventListener("click",addCanvas);
画布代码是:
private function addCanvas(oEvent:Event):void
{
caNew = new Canvas();
caNew.id = "cart"
caNew.name = "Shopping Cart";
caNew.x = 100;
caNew.y = 450;
caNew.width = 200;
caNew.height = 146;
caNew.setStyle("backgroundImage",cart_icon);
//caNew.setStyle("backgroundColor","#98AEEF");
this.addChild(caNew);
caNew.addEventListener(DragEvent.DRAG_ENTER, dragAcceptShop);
caNew.addEventListener(DragEvent.DRAG_DROP, dragDropShop);
laNew = new Label();
laNew.id = "contain"
laNew.text = "Shopping Cart";
laNew.x = 100;
laNew.y = 450;
laNew.width = 120;
laNew.height = 50;
this.addChild(laNew);
}
我做错了什么?就像我使用backgroundImage 一样,它工作正常,并且只有颜色有效。
I am dynamically creating a canvas, and I need a background image within the canvas. The canvas is created as it accepts drag drop but the background image does not show up.
The trigger for the canvas is:
buttonNew.addEventListener("click",addCanvas);
The canvas code is:
private function addCanvas(oEvent:Event):void
{
caNew = new Canvas();
caNew.id = "cart"
caNew.name = "Shopping Cart";
caNew.x = 100;
caNew.y = 450;
caNew.width = 200;
caNew.height = 146;
caNew.setStyle("backgroundImage",cart_icon);
//caNew.setStyle("backgroundColor","#98AEEF");
this.addChild(caNew);
caNew.addEventListener(DragEvent.DRAG_ENTER, dragAcceptShop);
caNew.addEventListener(DragEvent.DRAG_DROP, dragDropShop);
laNew = new Label();
laNew.id = "contain"
laNew.text = "Shopping Cart";
laNew.x = 100;
laNew.y = 450;
laNew.width = 120;
laNew.height = 50;
this.addChild(laNew);
}
What am I doing wrong? As if I use backgroundImage it works fine and only the colour works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有指定所使用的 Flex SDK 版本,但 backgroundImage 不是 Spark 主题中的可用样式。 Spark 是 Flex 4(及更高版本)项目的默认主题。 查看所有可用的样式 。
一个选项是将图像组件添加为画布上的第一个子组件。
You didn't specify which version of the Flex SDK you were using, but backgroundImage is not an available style in the Spark theme. Spark is the default theme for Flex 4 (and later) projects. Check out all available sytles.
One option is to add an Image component as the first child on the canvas.