2

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 work 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?

3
  • You can't have it as public static var?
    – user562566
    Apr 13, 2011 at 22:48
  • Also if you're having issue with your PDF library you might want to look at: alivepdf.bytearray.org.
    – user562566
    Apr 13, 2011 at 22:49
  • Actually the PDF library - purePDF - is GREAT! It is a port of the Java iText library. The only important thing it doesn't have from iText is the ChartFactory, so the developer ends up scrounging up code for piecharts, but other than that, its been great. Really good examples, and it is my new replacement for TCPDF ( a PHP library). Flash is GREAT for creating PDF reports - a pure PHP solution is too slow for 60 page reports with charts and graphs - takes several minutes to generate, whereas purePDF/Flash has it done in seconds. Apr 15, 2011 at 14:35

3 Answers 3

5

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.

2

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.

1
  • This really correct solution for constant vectors, opposite to public static var COLUMNWIDTHS: Vector.<Number>
    – radistao
    Jan 19, 2013 at 17:59
1

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.