1
我正在創建一個按鈕,我使用beginBitmapFill方法向它添加圖像。一切工作正常,問題是由一個Loader(加載)的圖像大於它實際上是Simplebutton圖像大於它實際上是
類創建按鈕
package mode {
\t import flash.display.Sprite;
\t import org.osmf.net.StreamingURLResource;
\t
\t public class LoadButton extends Sprite
\t {
\t \t public var Save;
\t \t public function LoadButton(x:uint,save:String,url:String)
\t \t {
\t \t \t var button:CustomSimpleButton = new CustomSimpleButton(url);
\t \t \t button.x = x;
\t \t \t Save = save;
\t \t \t addChild(button);
\t \t }
\t }
}
import flash.display.*;
import flash.display.Bitmap;
import flash.display.DisplayObject;
import flash.display.Shape;
import flash.display.SimpleButton;
import flash.events.*;
import flash.events.EventDispatcher;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.geom.Matrix;
class CustomSimpleButton extends SimpleButton
{
\t private var upColor:uint = 0xFFCC00;
\t private var overColor:uint = 0xCCFF00;
\t private var downColor:uint = 0x00CCFF;
\t private var sizew:uint = 100;
\t private var sizeh:uint = 88;
\t
\t public function CustomSimpleButton(url:String)
\t {
\t \t downState = new ButtonDisplayState(downColor, sizew,sizeh,url);
\t \t overState = new ButtonDisplayState(overColor, sizew,sizeh,url);
\t \t upState = new ButtonDisplayState(upColor, sizew,sizeh,url);
\t \t hitTestState = new ButtonDisplayState(upColor, sizew * 2,sizeh,url);
\t \t hitTestState.x = -(sizew/4);
\t \t hitTestState.y = hitTestState.x;
\t \t useHandCursor = true;
\t }
}
class ButtonDisplayState extends Shape
{
\t private var bgColor:uint;
\t private var size:uint;
\t private var sizeh:uint;
\t
\t public function ButtonDisplayState(bgColor:uint, sizew:uint,sizeh:uint,url:String)
\t {
\t \t this.bgColor = bgColor;
\t \t this.size = sizew;
\t \t this.sizeh = sizeh;
\t \t draw(url);
\t }
\t
\t private function draw(url:String):void
\t {
\t \t var myLoader:Loader = new Loader();
\t \t var image:Bitmap;
\t \t var uri = new URLRequest(url);
\t \t myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event)
\t \t {
\t \t \t image = new Bitmap(e.target.content.bitmapData);
\t \t \t graphics.beginBitmapFill(image.bitmapData);
\t \t \t graphics.drawRect(0, 0, 100, 88);
\t \t \t graphics.endFill();
\t \t });
\t \t myLoader.load(uri); \t
\t }
}
圖像如何是100x88
,因爲它是
如果我添加addChild它的作品,圖片是正確的大小,但我需要使用beginBitmapFill然後奈作品 – Rene
什麼是'奈'?我更新的答案包括另一個例子 – BadFeelingAboutThis
迪你找到一個解決方案?如果您發現我的答案有幫助,請立即註冊。如果它導致您的解決方案,請接受它。如果您找到了不同的解決方案,請自己回答問題。如果您仍然需要幫助,請更新您的問題或留下評論。 – BadFeelingAboutThis