ptfury
May 12th, 2008, 06:38 AM
hey :)
i have a problem making an horizontal scroll, it kinda makes the vertical one without scrolling :s
here is the code im using:
package project
{
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.utils.ByteArray;
import flash.display.SimpleButton;
public class Scroll extends MovieClip
{
private var _area:Sprite;
private var _container:MovieClip;
private var _scroller:Sprite;
//CommentList
public function Scroll()
{
if (this.area != null)
{
this.container.mask = this.area;
}
if (this.scroller != null)
{
this.scroller.addEventListener(MouseEvent.MOUSE_DO WN, this.startScroll);
this.scroller.stage.addEventListener(MouseEvent.MO USE_UP, this.stopScroll);
this.addEventListener(Event.ENTER_FRAME, this.doScroll);
}
}
public function get area():Sprite
{
return this._area;
}
public function set area(value:Sprite):void
{
this._area = value;
}
public function get container():MovieClip
{
return this._container;
}
public function set container(value:MovieClip):void
{
this._container = value;
}
public function get scroller():Sprite
{
return this._scroller;
}
public function set scroller(value:Sprite):void
{
this._scroller = value;
}
private function startScroll(e:MouseEvent):void
{
if (this.container.width > this.area.width)
{
this.scroller.startDrag(false,
new Rectangle(this.scroller.x, this.area.x, 0, this.area.width - this.scroller.width));
}
}
private function stopScroll(e:MouseEvent):void
{
this.scroller.stopDrag();
}
private function doScroll(e:Event):void
{
if (this.container.width > this.area.width)
{
//this.scroller.alpha=1;
var cy = this.container.x;
var ch = this.container.width;
var ay = this.area.x;
var ah = this.area.width;
var sy = this.scroller.x;
var sh = this.scroller.width;
var scrollAmount:Number = (ch - ah) / (ah - sh);
var targetX:Number = ay - ((sy - ay) * scrollAmount);
//trace(this.container.y + " - " + targetY);
this.container.x -= (this.container.x - targetX) / 5;
}
else
{
//this.scroller.alpha=0;
this.scroller.x = this.area.x;
this.container.x = this.area.x;
}
}
}
}
cheers :)
i have a problem making an horizontal scroll, it kinda makes the vertical one without scrolling :s
here is the code im using:
package project
{
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.utils.ByteArray;
import flash.display.SimpleButton;
public class Scroll extends MovieClip
{
private var _area:Sprite;
private var _container:MovieClip;
private var _scroller:Sprite;
//CommentList
public function Scroll()
{
if (this.area != null)
{
this.container.mask = this.area;
}
if (this.scroller != null)
{
this.scroller.addEventListener(MouseEvent.MOUSE_DO WN, this.startScroll);
this.scroller.stage.addEventListener(MouseEvent.MO USE_UP, this.stopScroll);
this.addEventListener(Event.ENTER_FRAME, this.doScroll);
}
}
public function get area():Sprite
{
return this._area;
}
public function set area(value:Sprite):void
{
this._area = value;
}
public function get container():MovieClip
{
return this._container;
}
public function set container(value:MovieClip):void
{
this._container = value;
}
public function get scroller():Sprite
{
return this._scroller;
}
public function set scroller(value:Sprite):void
{
this._scroller = value;
}
private function startScroll(e:MouseEvent):void
{
if (this.container.width > this.area.width)
{
this.scroller.startDrag(false,
new Rectangle(this.scroller.x, this.area.x, 0, this.area.width - this.scroller.width));
}
}
private function stopScroll(e:MouseEvent):void
{
this.scroller.stopDrag();
}
private function doScroll(e:Event):void
{
if (this.container.width > this.area.width)
{
//this.scroller.alpha=1;
var cy = this.container.x;
var ch = this.container.width;
var ay = this.area.x;
var ah = this.area.width;
var sy = this.scroller.x;
var sh = this.scroller.width;
var scrollAmount:Number = (ch - ah) / (ah - sh);
var targetX:Number = ay - ((sy - ay) * scrollAmount);
//trace(this.container.y + " - " + targetY);
this.container.x -= (this.container.x - targetX) / 5;
}
else
{
//this.scroller.alpha=0;
this.scroller.x = this.area.x;
this.container.x = this.area.x;
}
}
}
}
cheers :)