troubleshooting Question

Transfer of mobile action script package to mobile mxml code

Avatar of chrsyl
chrsyl asked on
Adobe FlashScripting LanguagesApache Flex
8 Comments1 Solution585 ViewsLast Modified:
Hi,
I put together a mobile action script that makes an arc. Then I tried to use this package in a mxml mobile code but did not succeed? Where am I failing?
Sincerely
chrsyl

mobile actionscript code:

package  com {
      import flash.display.DisplayObject;
      import flash.display.Graphics;
      import flash.display.Shape;
      import flash.display.Sprite;
      import flash.display.StageAlign;
      import flash.display.StageScaleMode;
      
      public class Arc extends Sprite {
            private var size:uint         = 80;
            private var bgColor:uint      = 0xFFCC00;
            private var borderColor:uint  = 0x666666;
            private var borderSize:uint   = 0;
            private var cornerRadius:uint = 9;
            private var gutter:uint       = 5;
            
            public function Arc() {
                  super();
                  
                  // support autoOrients
                  stage.align = StageAlign.TOP_LEFT;
                  stage.scaleMode = StageScaleMode.NO_SCALE;
                  
                  drawArc(90, 160, 50, 100, 30, 30 );      
                  refreshLayout();
            }
            
            private function refreshLayout():void {
                  var ln:uint = numChildren;
                  var child:DisplayObject;
                  var lastChild:DisplayObject = getChildAt(0);
                  lastChild.x = gutter;
                  lastChild.y = gutter;
                  for (var i:uint = 1; i < ln; i++) {
                        child = getChildAt(i);
                        child.x = gutter + lastChild.x + lastChild.width;
                        child.y = gutter;
                        lastChild = child;
                  }}
                        
            public  function drawArc(x : Number, y : Number, radius : Number, arc : Number, startAngle : Number, yRadius : Number ) : void {
                  
                  var target:Shape = new Shape();
                  
                  // if startAngle is undefined, startAngle = 0
                  if( startAngle == 0 ) {
                        startAngle = 0;
                  }
                  // if yRadius is undefined, yRadius = radius
                  if (yRadius == 0) {
                        yRadius = radius;
                  }
                  
                  // Init vars
                  var  segAngle : Number, theta : Number, angle : Number, angleMid : Number, segs : Number, ax : Number, ay : Number, bx : Number, by : Number, cx : Number, cy : Number;
                  // no sense in drawing more than is needed :)
                  if (abs( arc ) > 360) {
                        arc = 360;
                  }
                  // Flash uses 8 segments per circle, to match that, we draw in a maximum
                  // of 45 degree segments. First we calculate how many segments are needed
                  // for our arc.
                  segs = ceil( abs( arc ) / 45 );
                  // Now calculate the sweep of each segment
                  segAngle = arc / segs;
                  // The math requires radians rather than degrees. To convert from degrees
                  // use the formula (degrees/180)*Math.PI to get radians.
                  theta = -(segAngle / 180) * Math.PI;
                  // convert angle startAngle to radians
                  angle = -(startAngle / 180) * Math.PI;
                  // find our starting points (ax,ay) relative to the secified x,y
                  ax = x - Math.cos( angle ) * radius;
                  ay = y - Math.sin( angle ) * yRadius;
                  // if our arc is larger than 45 degrees, draw as 45 degree segments
                  // so that we match Flash's native circle routines.
                  target.graphics.lineStyle(1, 0x990000, .75);
                  if (segs > 0) {
                        target.graphics.moveTo( x, y );
                        // Loop for drawing arc segments
                        for (var i : int = 0; i < segs; ++i) {
                              // increment our angle
                              angle += theta;
                              // find the angle halfway between the last angle and the new
                              angleMid = angle - (theta / 2);
                              // calculate our end point
                              bx = ax + Math.cos( angle ) * radius;
                              by = ay + Math.sin( angle ) * yRadius;
                              // calculate our control point
                              cx = ax + Math.cos( angleMid ) * (radius / Math.cos( theta / 2 ));
                              cy = ay + Math.sin( angleMid ) * (yRadius / Math.cos( theta / 2 ));
                              // draw the arc segment
                              target.graphics.curveTo( cx, cy, bx, by );
                              addChild(target);
                        }}}
            
            
            private static function abs( value : Number ) : Number {
                  return value < 0 ? -value : value;
            }
            
            private static function ceil( value : Number) : Number {
                  return (value % 1) ? int( value ) + 1 : value;
            }}}

mxml code:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
      <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
      </fx:Declarations>
      <fx:Script>
            <![CDATA[      
                  import com.Arc;                  
            ]]>
      </fx:Script>
      
      <s:VGroup width="100%" height="100%"  horizontalAlign="left">
            
            <s:Imgae source="{myArc}" />
            
            
      </s:VGroup >
</s:View>
ASKER CERTIFIED SOLUTION
chrsyl

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros