so I’ve assisgned an assisngment to do a scrolling background which says The background is controlled by the user via the keyboard and moves based on either of the following key presses to make it move left and right:
- Left and Right Cursor Keys
- ‘A’ and ‘D’ Key
If there is no more background to see, the scrolling must stop.
but what I did was
package
{
import flash.display.*;
import flash.events.*;
import flash.ui.*
import flashx.textLayout.formats.BackgroundColor;
public class backgroundthatmove extends MovieClip
{
var bg1:Background;
var bg2:Foreground;
var bg3:Middleground;
var LEFT:Boolean;
var RIGHT:Boolean;
public function backgroundthatmove()
{
// constructor code
bg1 = new Background;
bg2 = new Foreground;
bg3 = new Middleground;
addChild(bg1);
addChild(bg2);
addChild(bg3);
bg1.gotoAndStop("bg3");
bg3.gotoAndStop("bg1");
//add Listneres to listen for keyboard Events
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPress);
stage.addEventListener(KeyboardEvent.KEY_UP,onKeyRelease);
//add Listners to listen for screen update
addEventListener(Event.ENTER_FRAME, gameLoop);
}
private function gameLoop(e:Event)
{
if(LEFT)
{
bg1.x += -5;
bg1.gotoAndStop("bg2");
}
if(RIGHT)
{
bg2.x += -5;
bg2.gotoAndStop("bg1");
}
if(!LEFT && !RIGHT)
{
bg1.gotoAndStop("bg2");
}
if(!RIGHT && !LEFT)
{
bg1.gotoAndStop("bg1");
}
}
private function onKeyPress(e:KeyboardEvent);
{
// Do something if a key is press
switch(e.keyCode)
{
case Keyboard.LEFT: // Left is pressed
LEFT = true; // sign left is pressed for animation
break;
case Keyboard.RIGHT: //Right is released
RIGHT = true; // signal right is released for animation
break;
}
}
private function onKeyRelease(e:KeyboardEvent);
{
// Do something if a key is release
switch(e.keyCode)
{
case Keyboard.LEFT: // Left is pressed
LEFT = false; // sign left is pressed for animation
break;
case Keyboard.RIGHT: //Right is released
RIGHT = false; // signal right is released for animation
break;
}
}
}
}
--------- under it says ----
Line 65 1126 function does not have a body
Line 81 1126 function does not have a body
you guys can email it me at anthonyamigleo2011@gmail.com I could send you the file so you know what my file was set up