AS3 rotation issue/bug need help.
Copy link to clipboard
Copied
Ok I have been converting a AS2 flash based sight to AS3. With the project I have to make new transitions for the pages. The client wants these transitions to be in 3d, which ive worked with before and have had no problems. However for the last few hours ive had this killer issue that wont go away.
When using rotationZ or rotationX on any element the rotation value is not based on 360 degrease but instead based on a random number. For example I can rotate a box on the stage by 0.03 and it will be ~rotated 180 degrease, but if I do the same rotation on another box on the stage it will go to ~40 degrease.
Im clueless to why this is happing and if I try to duplicate the error in another file it wont happen. So... anyone able to give me a heads up at what may be causing this?
For those asking how im rotating it.
box.rotationY = 45;
box2.rotationY = 90;
Copy link to clipboard
Copied
use that's a degrees/radians error but you'll have to show your code for specifics.
Copy link to clipboard
Copied
Ok... heres the min code for the error to happen my side.
If you need an XML you can make your own to test this using the fallowing structer or just use this.
---------------------------- XML Bellow ------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xml>
<page>
<name value="Home"/>
<background value=""/>
<content type="text">Hello this is random text? what the hell? what the duce?</content>
<x value="400"/>
<y value="20"/>
<content type="image">url to the image file</content>
<x value="400"/>
<y value="20"/>
</page>
</xml>
-------------------------------- AS3 Bellow -----------------------------
package {
import com.greensock.*; // this is a tweening class dont worrie about it
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
import flash.utils.*;
import flash.geom.*;
public class sps extends MovieClip {
var PAGES:MovieClip = new MovieClip();
var p_url:String="sps.xml"; // this generates content for pages loads and works fine dont worrie about it
var p_loader:URLLoader = new URLLoader();
var PageList:XMLList;
var rdy:Boolean = false;
public function sps() {
setFormats();
loadPages();
init();
}
public function init() {
addChild(PAGES);
PAGES.rotationY = 60; // This is were the problem is!
}
public function setFormats() {
ntf.color=0xFFFFFF;
ntf.font="Tahoma";
ntf.size=12;
ntf.align="center";
ntf.bold=true;
ntf.rightMargin=ntf.leftMargin=10;
}
public function loadPages() {
function onComplete(e:Event) {
p_loader.removeEventListener(Event.COMPLETE, onComplete);
var xmlData:XML=new XML(e.target.data);
PageList=xmlData.children();
var i:Number=0;
while (i < PageList.length()) {
makePage(PageList, PAGES);
i+=1;
}
}
p_loader.load(new URLRequest(p_url));
p_loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
}
public function makePage(pd:XML, p:MovieClip) {
var page:MovieClip =new MovieClip();
var pageCon:MovieClip = new MovieClip();
var i:Number=0;
while (i < pd.content.length()) {
if (pd.content.attributes()=="text") {
newText(pageCon, pd.content, pd.x.attributes(), pd.y.attributes());
}else if (pd.content.attributes()=="image") {
newImage(pageCon, pd.content, pd.x.attributes(), pd.y.attributes());
}else if (pd.content.attributes()=="video") {
}else if (pd.content.attributes()=="music") {
}else if (pd.content.attributes()=="subpage") {
}else if (pd.content.attributes()=="slider") {
}
i += 1;
}
pageCon.x-=472.5;
p.addChild(pageCon);
pageCon.addChild(page);
}
public function newText(p:MovieClip, t:String, x:Number, y:Number) {
var tf:TextField = new TextField();
tf.text = t;
tf.x=x;
tf.y=y;
p.addChild(tf);
return tf;
}
public function newImage(p:MovieClip, u:String, x:Number, y:Number) {
var f:URLRequest = new URLRequest(u);
var i:MovieClip = new MovieClip();
var l:Loader = new Loader();
i.x=x;
i.y=y;
l.load(f);
p.addChild(i);
function ps (e:ProgressEvent){
}
function lr(e:Event){
l.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, ps);
l.contentLoaderInfo.removeEventListener(Event.COMPLETE, lr);
i.addChild(l);
}
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, ps);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, lr);
return i;
}
}
}
Copy link to clipboard
Copied
NEVER nest named functions. that's your first error. fix that and see what problems remain:
-------------------------------- AS3 Bellow -----------------------------
package {
import com.greensock.*; // this is a tweening class dont worrie about it
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
import flash.utils.*;
import flash.geom.*;
public class sps extends MovieClip {
var PAGES:MovieClip = new MovieClip();
var p_url:String="sps.xml"; // this generates content for pages loads and works fine dont worrie about it
var p_loader:URLLoader = new URLLoader();
var PageList:XMLList;
var rdy:Boolean = false;
public function sps() {
setFormats();
loadPages();
init();
}
public function init() {
addChild(PAGES);PAGES.rotationY = 60; // This is were the problem is!
}
public function setFormats() {
ntf.color=0xFFFFFF;
ntf.font="Tahoma";
ntf.size=12;
ntf.align="center";
ntf.bold=true;
ntf.rightMargin=ntf.leftMargin=10;
}
public function loadPages() {
p_loader.load(new URLRequest(p_url));
p_loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
}function onComplete(e:Event) {
p_loader.removeEventListener(Event.COMPLETE, onComplete);
var xmlData:XML=new XML(e.target.data);
PageList=xmlData.children();
var i:Number=0;
while (i < PageList.length()) {
makePage(PageList, PAGES);
i+=1;
}
}
public function makePage(pd:XML, p:MovieClip) {
var page:MovieClip =new MovieClip();
var pageCon:MovieClip = new MovieClip();
var i:Number=0;
while (i < pd.content.length()) {
if (pd.content.attributes()=="text") {
newText(pageCon, pd.content, pd.x.attributes(), pd.y.attributes());
}else if (pd.content.attributes()=="image") {
newImage(pageCon, pd.content, pd.x.attributes(), pd.y.attributes());
}else if (pd.content.attributes()=="video") {
}else if (pd.content.attributes()=="music") {
}else if (pd.content.attributes()=="subpage") {
}else if (pd.content.attributes()=="slider") {
}
i += 1;
}
pageCon.x-=472.5;
p.addChild(pageCon);
pageCon.addChild(page);
}
public function newText(p:MovieClip, t:String, x:Number, y:Number) {
var tf:TextField = new TextField();
tf.text = t;
tf.x=x;
tf.y=y;
p.addChild(tf);
return tf;
}
public function newImage(p:MovieClip, u:String, x:Number, y:Number) {
var f:URLRequest = new URLRequest(u);
var i:MovieClip = new MovieClip();
var l:Loader = new Loader();
i.x=x;
i.y=y;
l.load(f);
p.addChild(i);
function ps (e:ProgressEvent){
}
function lr(e:Event){
l.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, ps);
l.contentLoaderInfo.removeEventListener(Event.COMPLETE, lr);
i.addChild(l);
}
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, ps);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, lr);
return i;
}
}
}
Copy link to clipboard
Copied
Your talking about the functions in newImage corect? The functions named PS and LR?
They are there caus I have a multi class file and its simple to do the nested functions rather then past all the classes into the post, but anyways took it out still wont rotate to 60 degrease.
I should note that their are no ERROR or WARNING messages that display when I run this file so the code works, its just that one thing. Im more so wonder if anyone has encouterd this error before and if they created a work around.
Copy link to clipboard
Copied
Are you sure the issue is not related to rotations being specified in degrees rather than radians? 60 degrees is not much rotation. 60 radians is a LOT of rotation. Perhaps you should read the docs relating to your rotation settings and see if the AS3 functions differ from the AS2 ones?
Copy link to clipboard
Copied
I think my issue is not coming across clear. My problem is that if I try to rotate and object it dose screwy.
Example::
I have a movieclip named box.
box.rotationY = 60;
trace(box.rotationY);
Results in the box being rotated to what looks like 45 by the fact that it turns it sideways. The trace confirms that it is rotated 60 thou.
Example 2::
I have a movieclip named box and a movieclip name cube
box.rotationY = 60;
cube.rotationY = 60;
trace(box.rotationY + " <-box --- cube-> " + cube.rotationY);
Results in box agian being roated ~45 but cube looking like its been rotated close to 20 or 200; The trace confirms that both are rotated 60.
In both examples the movieclips are attechted to the stage. The stage width and height however are less then the movieClip and the restults of the rotation variy with the stage width and height. This is because I have the stage resied to the full browser window in the code. Done through the emed of the flash.
Current version of flash is CS4 at work and CS5 at home, both display the same issue.
Copy link to clipboard
Copied
Do you know the difference between radians and degrees?
Copy link to clipboard
Copied
Yar I belive I do and http://math.rice.edu/~pcmi/sphere/drg_txt.html kinda confrims it but if you belive thats the issue please go ahead and give me a lengthy post explaining how to fix this through it.
Copy link to clipboard
Copied
OK great since you know I guess you don't need my help then.
Copy link to clipboard
Copied
create a new fla, add your (unrotated) box and cube in the new fla, add a input textfield and a button that applies a rotationY to both objects using the text (converted to a number) from the textfield.
publish a swf and html, upload to your server and post a link to your html, if you think there's still a problem.
(and your onComplete was nested. i showed how to unnest it.)
Copy link to clipboard
Copied
Ive been testing it and trying to narrow the source of the problem down. Through the testing I have already made a new file with just the movieclip and was able to rotate it freely and correctly. I belive the problem is somthing to do with the stage width and height and flash's 3d prespective and have started reading into that. I do thank you for trying to help me though.
Copy link to clipboard
Copied
you're welcome.

