2 Replies Latest reply on Aug 12, 2009 1:05 PM by geo-bart

    Lines visible in Flash player, but not in Flex

    geo-bart

      Hi,

       

      I made an 3D animation of the constellation Orion in Flash (see code below). It works properly.

       

      However, when I embed the animation in Flex using SWFLoader, I have a slight problem: the stars of the constellation are visible, the animation responds to mouse movements, depth scaling is OK...but the lines connecting the stars aren't visible. I'll post this problem also in a Flash forum (might be more AS related). Feel free to make the comparison for yourself.

       

      So any suggestions how I can make the lines visible? Can they be exported for Actionscript in the same way the movieclips are?

       

      Thanks alot,

       

      Bart

       

      Geography and sciences teacher

       

      I use AS3, Flash CS4 professional version 10.0.02, Flex Builder 3, IE8 and the latest Flash Player 10

       

       

      PS. Alex: thanks for the hint.

       

       

       

      //////////////////////////////////////////////////////////////////////////////// /::://////////////////////////////////////////////////////////////////////////// ///////////

       

       

      import __AS3__.vec.Vector;
      var balls:Array = new Array();
      var marks:Array = new Array();
      var numBalls:uint = 10;
      var fl:Number = 400;
      var vpX = 300;
      var vpY = 300;
      var commands:Vector.<int> = new Vector.<int>(50,true);
      var data:Vector.<Number> = new Vector.<Number>(100, true);
      var myHolder:Sprite = new Sprite();

      function init():void{

       


      stage.align = StageAlign.TOP_LEFT;
      stage.scaleMode = StageScaleMode.NO_SCALE;

       

      var xArray:Array = new Array();
      xArray = [251,182,279,326,294,271,251,219,385,294];

       

      var yArray:Array = new Array();
      yArray = [300, 117, 71, 141,270,285,300,459,425,270];

       

      var zArray:Array = new Array();
      zArray = [60,28,120, -50, 80, 160, 60, 40,60,80];

       

      for(var i:uint = 0;i < numBalls;i++){
       
        var ball:Ball = new Ball();
        var mark:Mark = new Mark();
        marks.push(ball);
        balls.push(ball);
        mark.xpos = ball.xpos = 0.6 * (xArray[i] - 210);
        mark.ypos = ball.ypos = 0.6 * (yArray[i] - 210);
        mark.zpos = ball.zpos = 0.6 * zArray[i];
       
        myHolder.addChild(ball);
        myHolder.addChild(mark);
       
       
       
      }

       

      addChild(myHolder);
      myHolder.x = vpX + 5;
      myHolder.y = vpY;
      addEventListener(Event.ENTER_FRAME, onEnterFrame);

       


      }


      function onEnterFrame(event:Event):void
      {

       

      var angleX:Number = (mouseY - vpY) * 0.00005;
      var angleY:Number = (mouseX - vpX) * 0.00005;

       

      for (var i:uint = 0;i<numBalls;i++){
       
        var ball:Ball = balls[i];
        rotateX(ball, angleX);
        rotateY(ball, angleY);
        var mark:Ball = marks[i];
       
        rotateX(mark, angleX);
        rotateY(mark,angleY);
        doPerspective(ball);
        doPerspective(mark);
       
       
      }

       

       

       


      sortZ();
      commands[0]= GraphicsPathCommand.MOVE_TO;
      data[0] = marks[0].x;
      data[1] = marks[0].y;

       

       

       

      for(i=1;i<numBalls;i++){
        data[2*i] = marks[i].x;
        data[2*i + 1] = marks[i].y;
        commands[i] = GraphicsPathCommand.LINE_TO;
       
       
      }

       

       

       


      myHolder.graphics.clear();
      myHolder.graphics.lineStyle(2, 0x000000, 1);
      myHolder.graphics.drawPath(commands, data);

       

      }

       


      function rotateX(ball:Ball, angleX:Number):void{
      var cosX:Number = Math.cos(angleX);
      var sinX:Number = Math.sin(angleX);

       

      var y1:Number = ball.ypos * cosX - ball.zpos * sinX;
      var z1:Number = ball.zpos * cosX + ball.ypos * sinX;
      ball.ypos = y1;
      ball.zpos = z1;

       


      }


      function rotateY(ball:Ball, angleY:Number):void{

       

      var cosY:Number = Math.cos(angleY);
      var sinY:Number = Math.sin(angleY);
      var x1:Number = ball.xpos * cosY - ball.zpos * sinY;
      var z1:Number = ball.zpos * cosY + ball.xpos * sinY;
      ball.xpos = x1;
      ball.zpos = z1;

       


      }

       

      function doPerspective(ball:Ball):void{
      if(ball.zpos  > -fl){
       
        var scale:Number = fl/(fl + ball.zpos);
        ball.scaleX = ball.scaleY = scale;
        ball.x = ball.xpos* scale;
        ball.y = ball.ypos * scale;
       
      }
      else {
       
        ball.visible = false;
       
      }
       
       

       

       

       


      }

       


      function sortZ():void{

       

      balls.sortOn("zpos", Array.NUMERIC | Array.DESCENDING);
      for(var i:uint;i<numBalls;i++){
       
        var ball:Ball = balls[i];
        myHolder.addChild(ball as Sprite);
       
      }

       

       

       

       

       

      }


      init();

      Attachments: