问题描述
这里是类:$ p $
package fnc {
import mx.containers.Canvas;
public class Deck extends Canvas {
protected var _chipCount:int;
$ b公共功能甲板(chipCount:int){
/ *将一些筹码与这套牌相关联* /
_chipCount = chipCount;
public function get chipCount():int {
return _chipCount;
这里是MXML: p>
<?xml version =1.0encoding =utf-8?>
< ns1:甲板horizontalCenter =0verticalCenter =0>
< / ns1:甲板>
< / mx:Application>
运行此应用程序会出现此错误:
ArgumentError:错误#1063:fnc :: Deck()上的参数计数不匹配。预计1,在mx.core :: Container / createComponentFromDescriptor()中得到0.
[C:\ autobuild \ 3.2.0 \ frameworks \projects\framework\src\mx\core \Container.as:3579]
在mx.core :: Container / createComponentsFromDescriptors()[C:\ autobuild\3.2.0\frameworks\projects\framework\src\mx\\ \\ core \Container.as:3493]
在mx.core :: Container / createChildren()[C:\ autobuild\3.2.0\frameworks\projects\framework\src\ mx.core ::Container.as:2589]
在mx.core :: UIComponent / initialize()[C:\ autobuild\3.2.0\frameworks\projects\framework\src \mx\core\UIComponent.as:5370]
在mx.core :: Container / initialize()[C:\ autobuild\3.2.0\frameworks\projects\framework\\ \\ src \mx\core\Container.as:2526]
在mx.core :: Application / initialize()[C:\autobuild\3.2.0\framewor ks\projects\framework\src\mx\core\Application.as:846]
at Practice / initialize()[C:\Documents and Settings\LocalService\My Documents\\ \\ Flex Builder 3 \Practice\src\Practice.mxml:0]
在mx.managers :: SystemManager / :\autobuild\\ \ 3.2 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3234)
在mx.managers :: SystemManager / :\autobuild \\ 3.2.0 \ frameworks \projects\framework\src\mx\managers\SystemManager.as:3064]
在mx.managers :: SystemManager / docFrameListener()[C:\ autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2916]
添加<$
cC> chipCount =0
version =1.0encoding =utf-8?>
< ns1:甲板chipCount =0horizontalCenter =0verticalCenter =0>
< / ns1:甲板>
< / mx:Application>
得到这个编译错误:
和描述路径资源位置创建时间Id
属性'chipCount'是只读的。练习/ src Practice.mxml第3行1242656555328 26
如何指定最初的筹码数量?
在回答brd6644的评论:
包
{
import mx.containers.Canvas;
public class Deck extends Canvas
{
protected var _chipCount:int;
private var chipCountChanged:Boolean;
public function Deck()
{
super();
public function set chipCount(value:int):void
{
if(chipCount!= value)
{
_chipCount =值;
chipCountChanged = true;
invalidateProperties();
//调用invalidateSize()如果改变chipCount的值可能会改变你的组件的大小
//调用invalidateDisplayList()如果改变chipCount的值需要重绘你的组件
}
}
public function get chipCount():int
{
return _chipCount;
保护函数commitProperties():void
{
super.commitProperties();
if(chipCountChanged)
{
chipCountChanged = false;
//这里更新由于chipCount新值而改变的属性。
}
}
}
}
Here's the Class:
package fnc {
import mx.containers.Canvas;
public class Deck extends Canvas {
protected var _chipCount:int;
public function Deck(chipCount:int) {
/* Associate some chips with this deck */
_chipCount = chipCount;
}
public function get chipCount():int {
return _chipCount;
}
}
}
Here's the MXML:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="fnc.*">
<ns1:Deck horizontalCenter="0" verticalCenter="0">
</ns1:Deck>
</mx:Application>
Running this application gets this error:
ArgumentError: Error #1063: Argument count mismatch on fnc::Deck(). Expected 1, got 0. at mx.core::Container/createComponentFromDescriptor()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:3579] at mx.core::Container/createComponentsFromDescriptors()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:3493] at mx.core::Container/createChildren()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:2589] at mx.core::UIComponent/initialize()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:5370] at mx.core::Container/initialize()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Container.as:2526] at mx.core::Application/initialize()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\Application.as:846] at Practice/initialize()[C:\Documents and Settings\LocalService\My Documents\Flex Builder 3\Practice\src\Practice.mxml:0] at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2009] at mx.managers::SystemManager/initializeTopLevelWindow()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3234] at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3064] at mx.managers::SystemManager/docFrameListener()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2916]
Adding chipCount="0"
to the MXML like this:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="fnc.*">
<ns1:Deck chipCount="0" horizontalCenter="0" verticalCenter="0">
</ns1:Deck>
</mx:Application>
Gets this compile error:
Severity and Description Path Resource Location Creation Time IdProperty 'chipCount' is read-only. Practice/src Practice.mxml line 3 1242656555328 26
How do I specify the initial chip count?
In answer to brd6644 comment :
package
{
import mx.containers.Canvas;
public class Deck extends Canvas
{
protected var _chipCount:int;
private var chipCountChanged:Boolean;
public function Deck()
{
super();
}
public function set chipCount(value:int):void
{
if (chipCount != value)
{
_chipCount = value;
chipCountChanged = true;
invalidateProperties();
//call invalidateSize() if changing chipCount value may change the size of your component
//call invalidateDisplayList() if changing chipCount value need a redraw of your component
}
}
public function get chipCount():int
{
return _chipCount;
}
override protected function commitProperties():void
{
super.commitProperties();
if (chipCountChanged)
{
chipCountChanged = false;
//here update properties that change because of chipCount new value.
}
}
}
}
这篇关于如何在自定义MXML标签中填充必需的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!