I found that exact forum post as well, but I do not understand how the problem was finally solved.
This is the entire code:
class Background extends MovieClip { //IqAndreas: Limit the speed the background is allowed to scroll (otherwise it might be rediculous) public const MAXSCROLLSPEED:int = 50; public const MINSCROLLSPEED:int = -50; //IqAndreas: Allow the background to scroll backwards as if the ship is traveling backwards //IqAndreas: Added a new property that allows the player to change the speed the background scrolls at. private var _scrollSpeed:int = 1 public property get scrollSpeed():int { if ((newSpeed <= MAXSCROLLSPEED) && (newSpeed >= MINSCROLLSPEED) {return _scrollSpeed;} else //Include this just in case newSpeed is not a valid number such as null {throw new Error("_scrollSpeed is not a valid value. Value must be between " & MINSCROLLSPEED & " and " & MAXSCROLLSPEED & "."} { public property set scrollSpeed(newSpeed:int = 1):void { if (newSpeed > MAXSCROLLSPEED) {throw new RangeError("The background speed must be less than " & MAXSCROLLSPEED & "."} else if (newSpeed < MINSCROLLSPEED) {throw new RangeError("The background speed must be more than " & MINSCROLLSPEED & "."} else if ((newSpeed <= MAXSCROLLSPEED) && (newSpeed >= MINSCROLLSPEED) {_scrollSpeed = newSpeed;} else //Include this just in case newSpeed is not a valid number such as null {throw new Error("The background speed must be between " & MINSCROLLSPEED & " and " & MAXSCROLLSPEED & "."} trace("_scrollSpeed set to",_scrollSpeed) { //this onEnterFrame function is a built-in function of every movie clip. It will execute all code inside it at frame rate (30 times a second) function onEnterFrame() { //move the background the amount of pixels as indicated by the speed _x -= this.scrollSpeed(); trace("Background moved",this.scrollSpeed()); //if it has travelled its entire length (2110 pixels) //IqAndreas: THIS CODE WAS CHANGED SO THAT IF THE BACKGROUND SIZE IS NOT 2110 PIXELS, IT STILL WILL WORK if(_x < this.width) { //then snap it back to zero, it will appear to scroll seamlessly _x = 0; } } }
Sorry about all the comments. I'm using someone else's code as a template, and then modifying it to make it suitable for my needs.
This file is saved as background.as and worked just fine before my changes to the code. Now the background will not scroll at all, however, the rest of the game will still run.
This is AS3, not AS2. Make sure you're compiling in AS3 first.
That's probably the problem. The original code was in AS2, and when I added code to it, all I have learnt is AS3, so I probably used the wrong syntax in several places.
How do you change an entire FLA document from AS2 to AS3? I don't mind changing the code manually, but where do you change which compiler Flash uses for that project?
Is there any way to have the main project written in AS2, and then have some of the external AS files written in AS3?
How different is the syntax between the two? I thought they just basically added more libraries.
@Iqandreas: To change it from AS3 to AS2, click on the stage and then choose Settings (beside Publish) from the property panel. And select AS2 from AS Version dropdown