Transfer of mobile action script package to mobile mxml code

chrsyl
chrsyl used Ask the Experts™
on
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>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Please help us help you.  When you say 'did not succeed', that does not really mean anything to other people.  Please describe what it should be doing and what it is doing and try to pinpoint the location where you think the problematic area is. Believe me on this.  You start losing your audiences as soon as your code runs more than 10 lines.

CyanBlue

Author

Commented:
Hi CyanBlue,
The action script produces an arc. But when implementing it in the mxml script no arc is produced as was expected. I think the problem is that the code in the mxml script is not appropriate to get the arc out of the action script. But I cannot solve it myself.
Sincerely¨chrsyl

Author

Commented:
I've requested that this question be deleted for the following reason:

1. Yes<br />2. Yes<br />3. Thank You!<br />
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
I am not trying to waste other people's time, but I have to object because I don't understand his reason behind 'yes, yes, thank you' note and love to know what he really means.  
People spend their own time to help others and those kinds of replies just throws me off.  :(

CyanBlue

Author

Commented:
Sorry if I have caused any bad feelings. That was indeed not my intention.
I just answered the questions posed when the question was ready to be deleted:
1. Have you responded to all of the Experts' questions and provided feedback for any proposed solutions? If not, please click "Cancel" and do so. Give the Experts a chance to respond before requesting that your question be deleted.
Yes
Did you find your own solution? If you did, please click "Cancel", post your solution, and then close the question by clicking "Accept as Solution" on your own post.
Yes
Participating Experts are given an opportunity to object prior to your question being deleted. If no objections are posted after four days, your question will be deleted automatically.
Thank you. Of course I thank the expert as the dialogue fueled me to see the problem otherwise and find the solution. Once mre, thank you.
chrsyl

Commented:
Now that makes more sense what you explain what that 'yes, yes, thank you' means.

It might have been better if you have said something like 'i've found my solution by doing xyz.' which the second question exactly says what to do.  The reason why the instruction says post your solution is because we want to keep the knowledge in writing so that other people who get stuck in the same problem can get help from what you have found out.  It's all about sharing knowledge.

None the less glad to hear that you've found the solution.

CyanBlue
Commented:
Communication not always easy, especially over mail ....
Here is what I arrived to:

mxml:
s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx"
                     width="300" height="100"
                     viewSourceURL="srcview/index.html"
                     creationComplete="addAS3Circle()">
      
      <fx:Script>
            import com.nl.funkymonkey.drawing.DrawingShapes;
            
            import mx.core.UIComponent;
            
            private function addAS3Circle():void{
                  
                  var component:UIComponent = new UIComponent();
                  
                  var s : Shape = new Shape( ); // Or Sprite of MovieClip or any other Class that makes use of the Graphics class
                  s.graphics.lineStyle( 4, 0xE16606 );
                  DrawingShapes.drawWedge( s.graphics, 50, 50, 10, 150, 60 );
                  component2.addChild( s );
                  addElement(component2);
                  }

etc

the AS3 file I used was that from funkymonkey.
Sincerely
chrsyl

Author

Commented:
Reason for selecting own solution: It addresses the problem and is working.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial