Copyright Year For Flash Pages

Generating a copyright notice on a Flash page is a relatively straightforward matter.

I. Print the Current Year

A. ActionScript 2

Regardless of whether one is using AS 2 or AS 3, a textbox needs to be created somewhere on the stage. The settings for this textbox should be as follows:

  1. Properties > Classic Text and Dynamic Text
  2. Paragraph > Align Right (if the textbox is on the right-hand side of the stage)

This textbox then needs to be instantiated with a name (such as copyrightTxt).

Following this, a new layer should be created and labelled Actionscript. Click on a keyframe within the Actionscript layer, and hit F9. With the following AS 2 code, the textbox will be populated with a copyright notice when the SWF file is run:

currDate = new Date();
currYear = currDate.getFullYear();

copyrightTxt.text = "\u00A9 Joseph Pecsenyicki 2010-" + currYear + ".  All Rights Reserved.";

Here, a new date object (currDate) is created, and the current year (with 4 digits) is extracted into the currYear variable. The current year is then output to the textbox along with the rest of the copyright information.

(\u invokes unicode in ActionScript; 00A9 is unicode for the copyright symbol.)

B. ActionScript 3

The textbox and layer creation procedure is mostly the same for AS 3, though one has a choice between using either 1) Classic Text with Dynamic Text or 2) TLF Text.

The AS 3 code is virtually the same as the AS 2 code, with minor syntactical differences:

var currDate:Date = new Date();
var currYear:String = String(currDate.getFullYear());

copyrightTxt.text = "\u00A9 Joseph Pecsenyicki 2010-" + currYear + ".  All Rights Reserved.";

II. Print Year or Range of Years

As discussed in a previous post, the code can be made slightly more sophisticated by way of conditional statements to prevent outputs such as this:

© Joseph Pecsenyicki 2013-2013. All Rights Reserved.

A. ActionScript 2

startYear = 2010;
currDate = new Date();
currYear = currDate.getFullYear();

if(startYear == currYear){
	copyrightTxt.text = "\u00A9 Joseph Pecsenyicki " + startYear + ".  All Rights Reserved.";
}
else{
	copyrightTxt.text = "\u00A9 Joseph Pecsenyicki " + startYear + "-" + currYear + ".  All Rights Reserved.";
}

B. ActionScript 3

var startYear:String = String(2010);
var currDate:Date = new Date();
var currYear:String = String(currDate.getFullYear());

if(startYear == currYear){
	copyrightTxt.text = "\u00A9 Joseph Pecsenyicki " + startYear + ".  All Rights Reserved.";
}
else{
	copyrightTxt.text = "\u00A9 Joseph Pecsenyicki " + startYear + "-" + currYear + ".  All Rights Reserved.";
}

The code in this post is word-wrapped. If copying & pasting, be wary of inserting carriage returns.

This entry was posted in Copyright Year Code, Flash, Flash - ActionScript 2, Flash - ActionScript 3. Bookmark the permalink.