package com.adam.etutorial
import flash.display.MovieClip; import flash.text.TextField; import flash.display.Sprite; import flash.text.TextFormat; import flash.display.Shape;爲什麼我無法從我的自定義類中獲取返回的值?
public class adamsboxmaker
{
//(boxWidth, boxHeight, lineColour, lineThickness, beginFillColour, fillIf, fontcolour, fontsize, fonttype, textFormat, textWidth, textHeight, text, Xoffset, Yoffset, textIf)
public function adamsboxmaker(boxWidth:Number,boxHeight:Number,lineColour:Number,lineThickness:int, beginFillColour:Number, fillIf:Boolean, fontColour:Number, fontSize:int, fontType:String, textWidth:Number, textHeight:Number, txt:String, Xoffset:Number, Yoffset:Number, textIf:Boolean)
{
createBox(boxWidth,boxHeight,lineColour,lineThickness, beginFillColour, fillIf, fontColour, fontSize, fontType, textWidth, textHeight, txt, Xoffset, Yoffset, textIf);
}
private function createBox(boxWidth:Number,boxHeight:Number,lineColour:Number,lineThickness:int, beginFillColour:Number, fillIf:Boolean, fontColour:Number, fontSize:int, fontType:String, textWidth:Number, textHeight:Number, txt:String, Xoffset:Number, Yoffset:Number, textIf:Boolean)
{
/*BUILD CONTAINER*/
var container:MovieClip = new MovieClip();
/*END CONTAINER*/
/*BUILD BOX*/
var theBox:Shape = new Shape();
container.addChild(theBox);
theBox.graphics.lineStyle(lineThickness, lineColour);
if (fillIf == true)
{
theBox.graphics.beginFill(beginFillColour);
}
theBox.graphics.moveTo(0, 0);
theBox.graphics.lineTo(boxWidth, 0);
theBox.graphics.lineTo(boxWidth, boxHeight);
theBox.graphics.lineTo(0, boxHeight);
theBox.graphics.lineTo(0, 0);
if (fillIf == true)
{
theBox.graphics.endFill();
}
/*END BOX*/
if (textIf == true)
{
/*BUILD FORMATTING*/
var myFormat:TextFormat = new TextFormat();
myFormat.color = fontColour;
myFormat.size = fontSize;
myFormat.font = fontType;
/*END FORMATTING*/
/*BUILD TEXTFIELD*/
var theText:TextField = new TextField();
theText.text = txt;
theText.x = Xoffset;
theText.y = Yoffset;
theText.width = textWidth;
theText.height = textHeight;
theText.wordWrap = true;
theText.setTextFormat(myFormat);
container.addChild(theText);
/*END TEXTFIELD*/
}
container.visible = false;
return container;
}
}
}
這是我在寫一個類,並閱讀了這是我第一次後裂紋。基本上,我希望能夠寫var txt:adamsboxmaker = new adamsboxmaker(parameters);
並將txt作爲返回的MovieClip的顯示對象。但這並沒有發生。 有人能指引我正確的方向嗎?
非常感謝你。 有沒有辦法通過adamsboxmaker = new adasboxmaker()獲得類似的結果。 ??林習慣訪問類的方式 – Adam 2010-07-22 00:07:07
@亞當是看到我更新的答案 – Allan 2010-07-22 00:23:26