Avatar of chrsyl
chrsyl
 asked on

Transfer of mobile action script package to mobile mxml code

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>
Adobe FlashApache FlexScripting Languages

Avatar of undefined
Last Comment
chrsyl

8/22/2022 - Mon
CyanBlue

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
chrsyl

ASKER
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
chrsyl

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

1. Yes<br />2. Yes<br />3. Thank You!<br />
Your help has saved me hundreds of hours of internet surfing.
fblack61
CyanBlue

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
chrsyl

ASKER
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
CyanBlue

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
chrsyl

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
chrsyl

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