Flex4 无法显示 Sprite,Shape,SimpleButton,TextField等显示对象,不知为何?能看下不

liang07118916 2011-01-06 09:45:18
<?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="onInit()">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[

import mx.core.UIComponent;

private var mainUi:UIComponent;
/**
* 主要显示对象,继承至displayobject类
*/
private var shape:Shape;
private var simpleBtn:SimpleButton;
private var textField:TextField;
private var sprite:Sprite;

/**
* 初始化显示对象
*/
private function onInit():void {
mainUi = new UIComponent();
mainUi.x = mainUi.y = 0;
mainUi.percentHeight = mainUi.percentWidth = 100;
this.addElement(mainUi);

shape = new Shape();
shape.x = 310;
shape.y = 0;
shape.width = shape.height = 100;
shape.graphics.beginFill(0x00FF00);
shape.graphics.drawCircle(0, 0, 20);
shape.graphics.endFill();
mainUi.addChild(shape);

simpleBtn = new SimpleButton();
simpleBtn.x = 0;
simpleBtn.y = 500;
simpleBtn.width = 80;
simpleBtn.height = 30;
mainUi.addChild(simpleBtn);

textField = new TextField();
textField.text = "123";
textField.x = 200;
textField.y = 500;
textField.width = 120;
textField.height = 30;
mainUi.addChild(textField);

sprite = new Sprite();
sprite.x = 200;
sprite.y = 200;
sprite.width = shape.height = 100;
sprite.graphics.beginFill(0x00FF00);
sprite.graphics.drawRect(0, 0, 50, 50);
sprite.graphics.endFill();
mainUi.addChild(sprite);
}
]]>
</fx:Script>

</s:Application>
...全文
600 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jwxkk 2011-01-07
  • 打赏
  • 举报
回复

<?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="onInit()">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
/**
* 主要显示对象,继承至displayobject类
*/
private var shape:Shape;
private var simpleBtn:SimpleButton;
private var textField:TextField;
private var sprite:Sprite;

/**
* 初始化显示对象
*/
private function onInit():void {

textField = new TextField();
textField.text = "123";
textField.x = 0;
textField.y = 0;
textField.width = 120;
textField.height = 30;
videoHolder.addChild(textField);


}
]]>
</fx:Script>



<s:SpriteVisualElement id="videoHolder" width="100%"
height="100%"/>

</s:Application>
liang07118916 2011-01-07
  • 打赏
  • 举报
回复
谢谢回复,呵呵
jwxkk 2011-01-07
  • 打赏
  • 举报
回复
找到问题了,原因是你drawCircle函数的参数确定的值在之前被定义了引起的冲突,注释了就好了


<?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="onInit()">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[

import mx.core.UIComponent;

private var mainUi:UIComponent;
/**
* 主要显示对象,继承至displayobject类
*/
private var shape:Shape;
private var simpleBtn:SimpleButton;
private var textField:TextField;
private var sprite:Sprite;

/**
* 初始化显示对象
*/
private function onInit():void {
mainUi = new UIComponent();
mainUi.x = mainUi.y = 0;
mainUi.percentHeight = mainUi.percentWidth = 100;
this.addElement(mainUi);

shape = new Shape();
//shape.x = 310;
//shape.y = 0;
//shape.width = shape.height = 100;
shape.graphics.beginFill(0x00FF00);
shape.graphics.drawCircle(0, 0, 20);
shape.graphics.endFill();
mainUi.addChild(shape);

simpleBtn = new SimpleButton();
simpleBtn.x = 0;
simpleBtn.y = 100;
simpleBtn.width = 80;
simpleBtn.height = 30;
mainUi.addChild(simpleBtn);

textField = new TextField();
textField.text = "123";
textField.x = 200;
textField.y = 500;
textField.width = 120;
textField.height = 30;
mainUi.addChild(textField);

sprite = new Sprite();
//sprite.x = 200;
//sprite.y = 200;
//sprite.width = shape.height = 100;
sprite.graphics.beginFill(0x00FF00);
sprite.graphics.drawRect(0, 0, 50, 50);
sprite.graphics.endFill();
mainUi.addChild(sprite);
}
]]>
</fx:Script>

</s:Application>

passself 2011-01-06
  • 打赏
  • 举报
回复
楼主没有把这些组件放到住mxml中吧,要不不会一个都不显示,你只是生成了,但是并没有添加

4,328

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计 Flex
社区管理员
  • Flex
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧