A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] scrolling background

  1. #1
    Senior Member
    Join Date
    Jan 2007
    Location
    Nottingham, England
    Posts
    263

    resolved [RESOLVED] scrolling background

    Hi,

    Wondering if any can see the problem with the scripting below: i've found some code online for a scrolling background and added it to my own code (intend to write my own eventually as i dont like have large chucks of code in my script i didnt write - makes it a pain in the arse to alter later on...) - the coding was written in as3 but altered slightly as it was written to be used within the movie and not in a document class.

    i can see what it's trying to do - update the x position of the frontPic everytime the timer fires, which in turn is set off by mouse movements. however when i test it, the frontpic loads in fine, but as soon as you move the mouse it disappears? I've clearly gone very wrong somewhere but cant see it...

    (also please forgive the general mess in the code. i've deleted large parts to make it easier to find what's relevant...)

    thanks

    PHP Code:
    package {
        
    //imports

        
    public class homePage extends MovieClip {

            private var 
    timer:Timer;
            private var 
    speed:Number 0.9;//variables

            
    public function homePage() {
                
    init();

            }
            private function 
    init():void {

                
    backPic=new backGrass  ;
                
    addChild(backPic);

                
    frontPic=new frontGrass  ;
                
    addChild(frontPic);

                
    timer = new Timer(40,0);
                

                
    this.addEventListener(Event.ADDED_TO_STAGE,stageActive);
                

            }
            function 
    stageActive(evt:Event):void {

                
    stage.scaleMode=StageScaleMode.NO_SCALE;
                
    stage.align=StageAlign.TOP_LEFT;
                
    stage.addEventListener(Event.RESIZE,resizeHandler);
                
                
                
    timer.addEventListener(TimerEvent.TIMERmoved);

                
    backPic.x=stage.stageWidth 2;
                
    backPic.y=stage.stageHeight;

                
    frontPic.x=stage.stageWidth 2;
                
    frontPic.y=stage.stageHeight;

                
                
    this.addEventListener(MouseEvent.MOUSE_MOVE,timerCalled);
                
            }
            function 
    resizeHandler(evt:Event):void {

                            
    //function
            
    }
            
            private function 
    timerCalled(event:MouseEvent):void {

            
    timer.stop();
            
    timer.start();
        }
        
            private function 
    moved(event:TimerEvent):void{
                
                
    frontPic.speed frontPic.speed stage.stageWidth frontPic.width mouseX stage.stageWidth;
            
    backPic.speed backPic.speed stage.stageWidth backPic.width mouseX stage.stageWidth;

            if (
    Math.abs(frontPic.stage.stageWidth frontPic.width root.mouseX stage.stageWidth) < && Math.abs(backPic.stage.stageWidth backPic.width root.mouseX stage.stageWidth) < 1) {
                
    frontPic.x=stage.stageWidth frontPic.width mouseX stage.stageWidth;
                
    backPic.x=stage.stageWidth backPic.width mouseX stage.stageWidth;
                
    timer.stop();


            }
            
    event.updateAfterEvent();
                
            }
            
            private function 
    onClickHome(event:MouseEvent):void {

                
    //function
            
            
    private function tweenFinished():void {

                
    //function
            
            
    private function homeIntroComplete(event:Event):void {

                
    //function
            
            
    private function homeLoading(event:ProgressEvent):void {
                
                
    //function
            
            
    public function homeLoadComplete(event:Event):void {

                
    //function
            
            
    private function homeOutroComplete(event:Event):void {

                
    //function
            
            
    private function homeBtnClicked(event:Event):void {

                   
    //function
        
    }


  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Have you done traces of the x value to see where the image goes?
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member
    Join Date
    Jan 2007
    Location
    Nottingham, England
    Posts
    263
    Hi Cancerinform,

    thanks for the advice. sorted it now - i had the x position of the frontpic centred instead of having it at the bottom left.

    just got to sort out the scrolling now - seems a little slow and jumpy?

    thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center