是否有可能在浏览器中运行这个简单的代码? 在.swf中,似乎都可以正常工作,但我无法在浏览器中调整.swf的大小... 舞台没有在HTML页面中调整大小。 通过.swf flile它就像一个魅力。 有人对此问题有所了解吗?Stage.RESIZE:是否可以在浏览器中运行此示例?
package com{
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.text.TextField;
public class Main extends MovieClip{
private static const ORANGE:int = 0xff9900;
var bg:MovieClip;
var bg_mask:MovieClip;
var marginx:int = 10;
var marginy:int = 10;
var display:MovieClip;
var displayTextField:TextField;
var ellipseWidth:int = 90;
var ellipseHeight:int = 90;
public function Main(){
super();
bg = new MovieClip();
bg_mask = new MovieClip();
display = new MovieClip();
displayTextField = new TextField();
this.addChild(bg);
this.addChild(bg_mask);
this.addChild(display);
this.display.addChild(displayTextField);
displayTextField.text = "";
displayTextField.x = ellipseWidth/Math.PI;
displayTextField.y = ellipseHeight/Math.PI;
stage.align = StageAlign.TOP_LEFT; // or StageAlign.TOP
stage.scaleMode = StageScaleMode.NO_SCALE;
drawBackground();
display.mask = bg_mask;
addListeners();
}
private function drawBackground(thickness:int=1,lineColor:int=0x000000,lineAlpha:Number=0.5,fillColor:int=ORANGE,fillAlpha:Number=0.5):void{
var g:Graphics = bg.graphics;
g.clear();
g.lineStyle(thickness,lineColor,lineAlpha);
g.beginFill(fillColor,fillAlpha);
g.drawRoundRect(marginx,marginy,this.stage.stageWidth-marginx*2,this.stage.stageHeight-marginy*2,ellipseWidth,ellipseHeight);
g.endFill();
}
private function drawMask():void{
var g:Graphics = bg_mask.graphics;
g.clear();
g.lineStyle(1,0x000000,0.3);
g.beginFill(0xcccccc,0.1);
g.drawRoundRect(marginx,marginy,this.stage.stageWidth-marginx*2,this.stage.stageHeight-marginy*2,90,90);
g.endFill();
}
private function addListeners():void{
stage.addEventListener(Event.ADDED,updateLabel);
stage.addEventListener(Event.RESIZE,updateLabel);
}
private function updateLabel(e:Event):void{
updateDisplay();
drawBackground();
drawMask();
}
private function updateDisplay():void{
var tf:TextField = displayTextField;
tf.text = ("{" + this.stage.stageWidth + ";" + this.stage.stageHeight + "}");
}
}
}
您需要显示将swf放入html页面的HTML标记。这可能是你发出谎言的地方。如果它使用固定大小,那么你在AS3代码中做了什么并不重要。 – BadFeelingAboutThis
你为什么不把它作为答案发表,而不是作为评论(我不能接受你的答案作为这种情况下的正确答案)? 它工作完美! 非常感谢。由于我将stage.scaleMode设置为: stage.scaleMode = StageScaleMode.NO_SCALE; 我以为这是重写我的Html css ... 愚蠢的错误! – tatactic