View Full Version : trace() won't work
infernosnow
June 16th, 2009, 12:18 PM
Trace() works in 2.0 files, but not in 3.0 files. Why?
EDIT: actually I just realized that I added a "C:\Documents and Settings\Account1\Desktop\as.as" classpath to Edit>Preferences>Actionscript>Actionscript 3.0 Settings> and that's why I am apparently not able to use trace() any more. I took the classpath out, but now I can't use the package and classes in my as.as file because it doesn't know where it's at. How am I supposed to tell it where my AS file is yet still use trace()?
tic
June 16th, 2009, 12:23 PM
could you post your code?
Couse trace() works fine in as3.0
public function init():void
{
trace("This should just trace a text")
}
infernosnow
June 16th, 2009, 01:52 PM
This is the code in my fla:
include "asfile.as";
import myPack.*;
var box1:Box = new Box();
This is the code in my actionscript file, which is named asfile.as
package
{
public class asfile
{} //have a class that is the same name as the .as file otherwise you get a f-ing error. wtf
public class point
{
public var x=0;
public var y=0;
public var z=0;
}
public class Box
{
public var x=0;
public var y=0;
public var z=0;
public var p1:point = new point();
public var p2:point = new point();
public var p3:point = new point();
public var p4:point = new point();
public var p5:point = new point();
public var p6:point = new point();
public var p7:point = new point();
public var p8:point = new point();
public function Box()
{
p1.x=-.5;
p1.y=.5;
p1.z=.5;
p2.x=.5;
p2.y=.5;
p2.z=.5;
p3.x=.5;
p3.y=-.5;
p3.z=.5;
p4.x=-.5;
p4.y=-.5;
p4.z=.5;
p5.x=-.5;
p5.y=.5;
p5.z=-.5;
p6.x=.5;
p6.y=.5;
p6.z=-.5;
p7.x=.5;
p7.y=-.5;
p7.z=-.5;
p8.x=-.5;
p8.y=-.5;
p8.z=-.5;
}
}
}
and here are a few of the errors I'm getting:
1151: A conflict exists with definition x in namespace internal.
1151: A conflict exists with definition y in namespace internal.
1151: A conflict exists with definition z in namespace internal.
1021: Duplicate function definition.
1025: Cannot redefine a final method.
1151: A conflict exists with definition p1 in namespace internal.
etc.... there's like a crapload of errors.
BoppreH
June 16th, 2009, 03:41 PM
First, you can't have more than one class definition per .as file. Second, I have no idea what are you trying to achieve with the include statement here and it's probably the source of the errors.
infernosnow
June 16th, 2009, 04:03 PM
One class per as file... ok. So if I have to specify an AS file for the Document Class thing in properties, but can only fit one in there, then how am I supposed to get the fla to recognize the classes in all my AS files? This is getting to be really freaking confusing. I don't know why I can't just write my stupid classes in the frames instead of in an actionscript file. That's how I've always done it before with other Actionscript I've written and I haven't had to include or import or have a specific AS file in the Document Class thing or any of that stuff before. I should be able to write
public class point
{
public var x=0;
public var y=0;
public var z=0;
}
anywhere on a frame and BOOM have a class, but it's not that easy apparently. I have spent about an hour looking up errors, looking at help files, etc. Grrrrr!!!!!!!!!!!!!
tic
June 16th, 2009, 04:07 PM
Agreed. no idea what you are trying to do.
But to fix a few of the errors.
point has to be Point.
and flash.geom.Point cant have a Z value.
Also there is no need to declaire the x=0 in a var.. seeing how this is standard (so does is y)
try something like this
package
{
import flash.display.MovieClip
import flash.geom.Point
}
public class asfile extends MovieClip
{
public var p1:point = new point();
public var p2:point = new point();
public var p3:point = new point();
public var p4:point = new point();
public var p5:point = new point();
public var p6:point = new point();
public var p7:point = new point();
public var p8:point = new point();
public function asfile():void
{
p1.x=-.5;
p1.y=.5;
p2.x=.5;
p2.y=.5;
p3.x=.5;
p3.y=-.5;
p4.x=-.5;
p4.y=-.5;
p5.x=-.5;
p5.y=.5;
p6.x=.5;
p6.y=.5;
p7.x=.5;
p7.y=-.5;
p8.x=-.5;
p8.y=-.5;
}
}
And just put "asfile" onder the class property in your main.
Although i doubt this will give you any visual output.....
If you want to draw something try
graphics.lineStyle(1, 0x000000x 1);
graphics.beginFill(0x000000);
graphics.moveTo(10,10);
graphics.lineTo(10.50);
graphics.lineTo(50,50);
graphics.lineTo(50,10);
graphics.endFill();
or if tou want the make boxes.. the simpeler
graphics.lineStyle(1, 0x000000x 1);
graphics.beginFill(0x000000);
graphics.drawRect(10,10,50,50);
graphics.endFill();
BoppreH
June 16th, 2009, 04:08 PM
One class per as file... ok. So if I have to specify an AS file for the Document Class thing in properties, but can only fit one in there, then how am I supposed to get the fla to recognize the classes in all my AS files? This is getting to be really freaking confusing. I don't know why I can't just write my stupid classes in the frames instead of in an actionscript file. That's how I've always done it before and I haven't had to include or import have a specific AS file in the Document Class thing or any of that stuff before. I should be able to write
public class point
{
public var x=0;
public var y=0;
public var z=0;
}
anywhere on a frame and BOOM have a class, but it's not that easy apparently. I have spent about an hour looking up errors, looking at help files, etc. Grrrrr!!!!!!!!!!!!!You are used to AS2 code. Declaring classes in frames is a bad habit and would get you trouble down the road any way. It's a good thing that AS3 forces us to clean our own mess.
And if you can't have more than one class per file, you simply create more files.
Open a new file named Box.as, for example, and define your class there:
package {
public class Box
{
public var x=0;
public var y=0;
public var z=0;
public var p1:point = new point();
public var p2:point = new point();
public var p3:point = new point();
public var p4:point = new point();
public var p5:point = new point();
public var p6:point = new point();
public var p7:point = new point();
public var p8:point = new point();
public function Box()
{
p1.x=-.5;
p1.y=.5;
p1.z=.5;
p2.x=.5;
p2.y=.5;
p2.z=.5;
p3.x=.5;
p3.y=-.5;
p3.z=.5;
p4.x=-.5;
p4.y=-.5;
p4.z=.5;
p5.x=-.5;
p5.y=.5;
p5.z=-.5;
p6.x=.5;
p6.y=.5;
p6.z=-.5;
p7.x=.5;
p7.y=-.5;
p7.z=-.5;
p8.x=-.5;
p8.y=-.5;
p8.z=-.5;
}
}
}
Then go to your timeline/document class file and simply call "import Box". BAAM, you have your class.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.