?
Solved

Scroll bar animation with forward and back buttons only?

Posted on 2009-02-12
3
Medium Priority
?
1,548 Views
Last Modified: 2012-05-06
Hey there-

I have a Sprite that when wider than the stage creates and displays two buttons, a forward and back button.  So far this successfully scrolls the Sprite across the screen in either direction.  But what if I wanted to create bounds for the scroll animation?  

For instance, stop the animation from moving any further left if the Sprite.width crosses a certain point or vise versa, disallow the Sprite.x to move forward from the stage's 0 X origin? Oh and grey out the buttons when one is rendered useless in terms of the bounds created.  

Thanks! Any help is appreciated!  I attached a .gif for visual purposes.
var containerObj:Sprite = new Sprite();
containerObj.x = 0;
containerObj.y = 0;
containerObj.width = 400;
//stage.stageWidth = 300;
 
checkBounds();
 
function checkBounds():void {
	if (containerObj.width >= stage.stageWidth) {
		displaySliders();
	}
}
 
function displaySliders():void {
	var btnContainer Sprite = new Sprite();
	var forBtn:Sprite = new Sprite();
	var backBtn:Sprite = new Sprite();
	foBtn.width = 20
	backBtn.width = 20;
	forBtn.x = 0;
	backBtn.x = forBtn.width;
	addChild(btnContainer);
	btnContainer.addChild(forBtn);
	btnContainer.addChild(backBtn);
	btn.addEventListener(MouseEvent.CLICK, clickBtn);
}
 
var begin:Number = containerObj.x;
var finish:Number = 0;
 
private function clickBtn(evt:MouseEvent):void {
	beginPos = containerObj.x;
	finishPosR = containerObj.x - 40;
	finishPosL = containerObj.x + 40;
	
	if (evt.target==lBtn) {
		var myTween1:Tween=new Tween(containerObj,"x",Strong.easeOut,beginPos,finishPosL,.5,true);
	}
	if (evt.target==rBtn) {
		var myTween2:Tween=new Tween(containerObj,"x",Strong.easeOut,beginPos,finishPosR,.5,true);
		}
	}
}

Open in new window

scroll-bar-dia.gif
0
Comment
Question by:worked
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Eaddy Barnes
ID: 23624976
You would have to introduce a line of code in case the x location of the containerObg exceeds the width of the stage.

the script would look like the following.

//this would keep it from passing the right side of the stage
 
if(containerObj.x >= stage.stageWidth)
{
containerObj.x = (stage.stageWidth - containerObj.width);
}
 
//this would keep it from passing the left side of the stage
 
if(containerObj.x <= (stage.stageWidth - stage.stageWidth))
{
containerObj.x = (stage.stageWidth - stage.stageWidth );
}

Open in new window

0
 

Author Comment

by:worked
ID: 23628627
So where would I put this code exactly?  I'm not sure where I would place the if ( conditional )...
0
 
LVL 11

Accepted Solution

by:
Eaddy Barnes earned 2000 total points
ID: 23629379
here is a peace of your code with the if statements inside:

private function clickBtn(evt:MouseEvent):void {
        beginPos = containerObj.x;
        finishPosR = containerObj.x - 40;
        finishPosL = containerObj.x + 40;
        
        if (evt.target==lBtn) {
                if(finishPosL >= (stage.stageWidth - containerObj.width))
{
finishPosL = (stage.stageWidth - containerObj.width);
}
				
				var myTween1:Tween=new Tween(containerObj,"x",Strong.easeOut,beginPos,finishPosL,.5,true);
        }
		
        if (evt.target==rBtn) {
			if(finishPosR <= (stage.stageWidth - stage.stageWidth))
{
finishPosR = (stage.stageWidth - stage.stageWidth );
}
                var myTween2:Tween=new Tween(containerObj,"x",Strong.easeOut,beginPos,finishPosR,.5,true);
                }
        }
}

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question