Flex 动作脚本中的 setStyle backgroundImage 不起作用

发布于 2024-12-12 13:37:46 字数 1235 浏览 0 评论 0原文

我正在动态创建画布,并且我需要画布内的背景图像。画布在接受拖放时创建,但背景图像不显示。

画布的触发器是:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难理解 2024-12-19 13:37:46

您没有指定所使用的 Flex SDK 版本,但 backgroundImage 不是 Spark 主题中的可用样式。 Spark 是 Fl​​ex 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文