Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-16-2012, 04:52 AM   #1
JeffLebowski
Registered User
 
Join Date: Apr 2012
Posts: 7
Default Scrolling Code Problem

I am extremely new to actionscript and have begun working on a code for a class that causes background elements to scroll and loop when you push a button. Here is the code as I have currently written it;

ActionScript Code:
// add elements to the stage // create variables var hills1:BgroundHills = new BgroundHills(); var hills2:BgroundHills = new BgroundHills(); var grass1:BgroundGrass = new BgroundGrass(); var grass2:BgroundGrass = new BgroundGrass(); // add children addChild(hills1); addChild(hills2); addChild(grass1); addChild(grass2); // set default positions hills1.x = 0; hills2.x = hills1.width; grass1.x = 0; grass2.x = grass1.width; // variable to control scroll speed var scrollSpeed:Number = 0; // variable to alternate scrolling on/off var scrolling:Boolean = false; // listen to see if scrolling and update scroll speed accordingly stage.addEventListener(Event.ENTER_FRAME, checkScrolling); function checkScrolling(event:Event):void {     if (scrolling = true) {         scrollSpeed = 2;     } else {         scrollSpeed = 0;     } } // listen to see if element positions need updating stage.addEventListener(Event.ENTER_FRAME, updatePosition); function updatePosition(event:Event):void {     hills1.x -= scrollSpeed;     hills2.x -= scrollSpeed;     grass1.x -= scrollSpeed;     grass2.x -= scrollSpeed; }

When I test the current script, even though scrolling is set to false by default, the elements hills1, hills2, grass1, and grass2 begin to scroll. Upon tracing the scrollSpeed it appears it gets set to 2 almost the moment it compiles.

I am unsure as to where I have gone wrong here as the code appears perfectly fine to me up until this point and I have received no compile errors.

If anyone could offer help it would be greatly appreciated.
JeffLebowski is offline   Reply With Quote
Old 04-16-2012, 07:31 AM   #2
JeffLebowski
Registered User
 
Join Date: Apr 2012
Posts: 7
Default Scrolling BGround Code Troubles

I am extremely new to actionscript and have begun working on a code for a class that causes background elements to scroll and loop when you push a button. Here is the code as I have currently written it;

ActionScript Code:
// add elements to the stage // create variables var hills1:BgroundHills = new BgroundHills(); var hills2:BgroundHills = new BgroundHills(); var grass1:BgroundGrass = new BgroundGrass(); var grass2:BgroundGrass = new BgroundGrass(); // add children addChild(hills1); addChild(hills2); addChild(grass1); addChild(grass2); // set default positions hills1.x = 0; hills2.x = hills1.width; grass1.x = 0; grass2.x = grass1.width; // variable to control scroll speed var scrollSpeed:Number = 0; // variable to alternate scrolling on/off var scrolling:Boolean = false; // listen to see if scrolling and update scroll speed accordingly stage.addEventListener(Event.ENTER_FRAME, checkScrolling); function checkScrolling(event:Event):void {     if (scrolling = true) {         scrollSpeed = 2;     } else {         scrollSpeed = 0;     } } // listen to see if element positions need updating stage.addEventListener(Event.ENTER_FRAME, updatePosition); function updatePosition(event:Event):void {     hills1.x -= scrollSpeed;     hills2.x -= scrollSpeed;     grass1.x -= scrollSpeed;     grass2.x -= scrollSpeed; }

When I test the current script, even though scrolling is set to false by default, the elements hills1, hills2, grass1, and grass2 begin to scroll. Upon tracing the scrollSpeed it appears it gets set to 2 almost the moment it compiles.

I am unsure as to where I have gone wrong here as the code appears perfectly fine to me up until this point and I have received no compile errors.

If anyone could offer help it would be greatly appreciated.
JeffLebowski is offline   Reply With Quote
Old 04-16-2012, 07:34 AM   #3
Poony
Flash Developer
 
Poony's Avatar
 
Join Date: Aug 2011
Location: Sweden
Posts: 366
Default

You're missing a "=" in your if statement
ActionScript Code:
if (scrolling == true) {
Poony is offline   Reply With Quote
Old 04-16-2012, 02:43 PM   #4
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 1,888
Default

you are using the assignment operator (=); use the equality operator (==)
[afz]snickelfitz is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:43 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.