AS3.0高手来帮忙下 谢谢 类 TestRect$ 必须继承 Sprite 的属性,才能链接到根。
我是新手,不知道这是什么问题,对照AS3.0COOKBOOK做的怎么不行呢?我建立了一个ActionScriptProject写好后,这样提示:TypeError:Err...
我是新手,不知道这是什么问题,对照AS3.0 COOKBOOK做的 怎么不行呢?
我建立了一个ActionScript Project
写好后,这样提示:
TypeError: Error #2023: 类 TestRect$ 必须继承 Sprite 的属性,才能链接到根。
/*********************代码如下*************************
package {
import flash.display.*
import flash.text.*;
import flash.filters.DropShadowFilter;
public class TestRect extends SimpleButton
{
private var _text:String;
private var _width:Number;
private var _height:Number;
public function TestRect(text:String,width:Number,height:Number)
{
_text=text;
_width=width;
_height=height;
upState=createUpState();
overState=createOverState();
downState=createDownState();
hitTestState=upState;
}
private function createUpState( ):Sprite {
var sprite:Sprite = new Sprite( );
var background:Shape = createdColoredRectangle( 0x33FF66 );
var textField:TextField = createTextField( false );
sprite.addChild( background );
sprite.addChild( textField );
return sprite;
}
private function createOverState( ):Sprite {
var sprite:Sprite = new Sprite( );
var background:Shape = createdColoredRectangle( 0x70FF94 );
var textField:TextField = createTextField( false );
sprite.addChild( background );
sprite.addChild( textField );
return sprite;
}
private function createDownState( ):Sprite {
var sprite:Sprite = new Sprite( );
var background:Shape = createdColoredRectangle( 0xCCCCCC );
var textField:TextField = createTextField( false );
sprite.addChild( background );
sprite.addChild( textField );
return sprite;
}
private function createdColoredRectangle( color:uint ):Shape {
var rect:Shape = new Shape( );
rect.graphics.lineStyle( 1, 0x000000 );
rect.graphics.beginFill( color );
rect.graphics.drawRoundRect( 0, 0, _width, _height, 15 );
rect.graphics.endFill( );
rect.filters = [ new DropShadowFilter( 2 ) ];
return rect;
}
private function createTextField( downState:Boolean ):TextField {
var textField:TextField = new TextField( );
textField.text = _text;
textField.width = _width;
var format:TextFormat = new TextFormat( );
format.align = TextFormatAlign.CENTER;
textField.setTextFormat( format );
textField.y = ( _height - textField.textHeight ) / 2;
textField.y -= 2; // Subtract 2 pixels to adjust for offset
if ( downState ) {
textField.x += 1;
textField.y += 1;
}
return textField;
}
}
}
对了,在Flex build 3 里面建立工程写的。 展开
我建立了一个ActionScript Project
写好后,这样提示:
TypeError: Error #2023: 类 TestRect$ 必须继承 Sprite 的属性,才能链接到根。
/*********************代码如下*************************
package {
import flash.display.*
import flash.text.*;
import flash.filters.DropShadowFilter;
public class TestRect extends SimpleButton
{
private var _text:String;
private var _width:Number;
private var _height:Number;
public function TestRect(text:String,width:Number,height:Number)
{
_text=text;
_width=width;
_height=height;
upState=createUpState();
overState=createOverState();
downState=createDownState();
hitTestState=upState;
}
private function createUpState( ):Sprite {
var sprite:Sprite = new Sprite( );
var background:Shape = createdColoredRectangle( 0x33FF66 );
var textField:TextField = createTextField( false );
sprite.addChild( background );
sprite.addChild( textField );
return sprite;
}
private function createOverState( ):Sprite {
var sprite:Sprite = new Sprite( );
var background:Shape = createdColoredRectangle( 0x70FF94 );
var textField:TextField = createTextField( false );
sprite.addChild( background );
sprite.addChild( textField );
return sprite;
}
private function createDownState( ):Sprite {
var sprite:Sprite = new Sprite( );
var background:Shape = createdColoredRectangle( 0xCCCCCC );
var textField:TextField = createTextField( false );
sprite.addChild( background );
sprite.addChild( textField );
return sprite;
}
private function createdColoredRectangle( color:uint ):Shape {
var rect:Shape = new Shape( );
rect.graphics.lineStyle( 1, 0x000000 );
rect.graphics.beginFill( color );
rect.graphics.drawRoundRect( 0, 0, _width, _height, 15 );
rect.graphics.endFill( );
rect.filters = [ new DropShadowFilter( 2 ) ];
return rect;
}
private function createTextField( downState:Boolean ):TextField {
var textField:TextField = new TextField( );
textField.text = _text;
textField.width = _width;
var format:TextFormat = new TextFormat( );
format.align = TextFormatAlign.CENTER;
textField.setTextFormat( format );
textField.y = ( _height - textField.textHeight ) / 2;
textField.y -= 2; // Subtract 2 pixels to adjust for offset
if ( downState ) {
textField.x += 1;
textField.y += 1;
}
return textField;
}
}
}
对了,在Flex build 3 里面建立工程写的。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询