Avatar of 1Cougar
1Cougar
 asked on

Actionscript 3.0 rotate embedded text

Hello,

I would like to create a class that takes a string and spaces the letters evenly around a circle.  I have tried to check out text.rotation, but the direction of the text always is "right to left" even once rotated.  I would like each individual character to follow the path of the circle (ie at the bottom a letter in the string would be upside down).  Then, I would like to spin this circle of text.

Any pointers on how to do this would be much appreciated!

Cheers!
Web Development SoftwareAdobe Flash

Avatar of undefined
Last Comment
blue-genie

8/22/2022 - Mon
1Cougar

ASKER
Hi again,

I found a sample of this from another post at: http://www.peterjoel.com/Samples/circletext.php

I am trying to adapt the code and put it in a package, but I am getting an error.  In my main movie I call:

var myCircleText:DrawCircleText = new DrawCircleText("This is fun!");
      addChild(myCircleText);

This is the output:

This is fun!
ReferenceError: Error #1069: Property 0 not found on DrawCircleText and there is no default value.
      at DrawCircleText/init()
      at DrawCircleText()
      at contentTestPlay_fla::MainTimeline/init()
      at contentTestPlay_fla::MainTimeline/frame1()

Does anyone have an idea what I'm doing wrong?

Thanks again!
package {
	import flash.display.Sprite;
	import flash.events.Event;
 
	public class DrawCircleText extends Sprite {
		public var thisText:String;
		public var defaultStyle={spacing:4, size:30, fontID:"font1", col:0x000000}
		public var defaultCircle={x:0,y:0,radius:150,angle:0}
		public var theta = (defaultCircle.angle+180)*Math.PI/180;
		public var r:Number = defaultCircle.radius;
		public var spac:Number = defaultStyle.spacing;
		public var size:Number = defaultStyle.size;
		
		public function DrawCircleText(myText:String) {
			thisText = myText;
			init();
			
		}
		
		public function init():void {
			
			trace(thisText);
			var L:int = thisText.length;
			var cWidth0:Number=0;
			var cWidth1:Number=0;
			var c;
			for(var i:int=0; i<L; i++){
				c=thisText.substr(i,1);
				if(c==" "){
					cWidth0 = size/2+spac;
					
				} else {
					this[i]._xscale=size;
					trace(this[i]._xscale);
					this[i]._yscale=size;
					cWidth1=this[i]._width/2;
					trace("before theta");
					theta+= Math.atan((cWidth1+cWidth0+(i?spac:0))/r);
					trace("after theta");
					cWidth0=cWidth1;
					this[i]._x=Math.cos(theta)*r;
					this[i]._y=Math.sin(theta)*r;
					this[i]._rotation = theta*180/Math.PI+90;
					
				}
				
			}
			
		}
 
	}
 
 
}

Open in new window

blue-genie

that example is an AS1 example.
how are you implementing this package? if i copy your code as is - i'm not getting that same error.
1Cougar

ASKER
Hi,

I am just calling it like this in a main fla:

var myCircleText:DrawCircleText = new DrawCircleText("This is fun!");
      addChild(myCircleText);

Does the code work for you?  I was trying to use it in an AS3 application, so maybe that is the issue?

Thanks again!
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
blue-genie

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.