Actionscript代码在Adobe Flash中运行良好,但在Flash Player或html中运行不正常

时间:2016-10-16 02:18:16

标签: actionscript-3 actionscript flash

我在ActionScript 3.0中编写了代码(使用CS4),在Flash编程接口中执行得很好。当我将它作为.swf或.html发布时,使用Flash Player或浏览器运行它们只会给出一个空白窗口。

可能相关:代码分为两部分,主线和包,但我假设Flash将这两部分一起发布。这一切都在一个框架中运行。

import Quadrilateral;
import flash.display.Stage; 
import flash.display.StageAlign; 
import flash.display.StageScaleMode; 
var pow:Function = Math.pow;
var cos:Function = Math.cos;
var sin:Function = Math.sin;
var acos:Function = Math.acos;
var PI:Number = Math.PI;

        var canvas:Sprite = new Sprite();
        var gr:Graphics = canvas.graphics;
        canvas.alpha = .6;
        this.addChild(canvas);
        var offset:Point = new Point(200,170);
        var a:Number=160;                       //a, b, and c are side lengths
        var c:Number=135;
        var angleb:Number=52*PI/180;        //anglea and angleb are the angles at vertex A and B
        var C:Point = new Point(a*cos(angleb), a*sin(angleb)).add(offset);      //A, B, and C are vertices 
        var B:Point = new Point(0,0).add(offset);
        var A:Point = new Point(c,0).add(offset);   
        var b:Number = Point.distance(C,A);
        var anglea:Number = acos((pow(b,2)+pow(c,2)-pow(a,2))/(2*c*b));
        var anglec:Number = PI - anglea - angleb;
//the following are the feet of altitudes from A to side a, B to side B, etc.
        var aA:Point = new Point(c*pow(cos(angleb),2), c*cos(angleb)*sin(angleb)).add(offset);
        var bB:Point = new Point(c*pow(sin(anglea),2), c*cos(anglea)*sin(anglea)).add(offset);
        var cC:Point = new Point(a*cos(angleb), 0).add(offset);
        var colors:Array = new Array(0xFF0000, 0x0009F0, 0x990099, 0x990099, 0x990099, 0xFF0000);
        var triangleColor:Number = 0x20D1D1;
        var steps:Number = 100;
        var timer = new Timer(10000, 1);    

        drawTriangle(A,B,C);
        var quada1:Quadrilateral = new Quadrilateral(B, aA,  a, colors[0], steps, canvas, 1);
        var quadb1:Quadrilateral = new Quadrilateral(A, bB,  b, colors[1], steps, canvas, -1);
        var quadc1:Quadrilateral = new Quadrilateral(C, bB,  b, colors[2], steps, canvas, 1);

/*      var quada2:Quadrilateral = new Quadrilateral(C, aA,  a, Point.distance(B,bB), colors[colorcount++], steps, canvas, -1);
        var quadb2:Quadrilateral = buildRectangle(C, bB, -b, B);
        var quadc2:Quadrilateral = buildRectangle(cC, B, c, C);
        */
        quada1.drawSquare(C, aA);
        quadb1.drawSquare(B, cC);
        quadc1.drawSquare(A, bB);
        gr.lineStyle(1,0xA0A0A0);
        connect(A,aA);
        connect(B,bB);
        connect(C,cC);
        quada1.go(A, angleb, -1, 0);
        timer.addEventListener(TimerEvent.TIMER_COMPLETE, nextside);
        timer.start();
        stop();
        function nextside(e:TimerEvent) {
            quadb1.go(B, anglea, 1, 0);
            timer.removeEventListener(TimerEvent.TIMER_COMPLETE, nextside);
            timer.addEventListener(TimerEvent.TIMER_COMPLETE, lastside);
            timer.start();
        }
        function lastside(e:TimerEvent) {
            quadc1.go(B, anglec, -1, -(anglea+anglec));
            timer.stop();
        }
        function drawTriangle(p1:Point, p2:Point, p3:Point) {
            gr.beginFill(triangleColor);
            gr.moveTo(p1.x, p1.y);
            gr.lineTo(p2.x, p2.y);
            gr.lineTo(p3.x, p3.y);
            gr.endFill();
        }
        function connect(p1:Point, p2:Point) {
            gr.moveTo(p1.x, p1.y);
            gr.lineTo(p2.x, p2.y);
        }

0 个答案:

没有答案