I am using purePDF - a PDF library for AS3 - to setup some reports. I want to use the same code to load up a dynamic number of headers and corresponding columns of data. But I have this one bit of code in the way:
public static const COLUMNWIDTHS: Vector.<Number> = Vector.<Number>( [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3] );
I have tried to w开发者_Go百科ork with this COLUMNWIDTHS issue, but it seems the library wants this to be setup as a public static const - I can't have it MY way - a public var. I dabble alot with AS3, but haven't had this problem till I started modifying this code for a project.
How do I get around this issue?
I'm not completely sure I understand your problem. But it looks like you want to change COLUMNWIDTHS
dynamically, but also it must be a static const
.
If that's the problem, you could fix it declaring your Vector
like this:
public static const COLUMNWIDTHS: Vector.<Number> = new Vector.<Number>();
Then, update its contents, for instance:
for (var i:int = 0; i < 10; i++) {
COLUMNWIDTHS[i] = 3;
}
Although it may look counterintuitive at first, the fact that COLUMNWIDTHS
is declared as const
doesn't mean you can't change the object's contents. It just means that the reference is constant. It points to one object, and you cannot make it point to another one. That is, you can't re-assign COLUMNWIDTHS
, but you definitely can change its contents.
I just had to look into this same question. Here is the best answer I was able to come up with:
public static const COLUMNWIDTHS: Vector.<Number> = new <Number>[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3];
It works in Flash 10 at least.
Okay, people, you're thinking too hard on this question. The answer is simple, and I ended figuring it out myself, about 5 minutes after posting, but my computer crashed right after I tested the solution (no fault of the code - my stupid laptop just does that once in awhile due to overheating of the i3 core [getting another laptop soon]).
Ascension systems - you are right - the following :
public static const COLUMNWIDTHS: Vector.<Number>
Needs to be :
public static var COLUMNWIDTHS: Vector.<Number>
Pretty simple solution!
精彩评论