PDA

View Full Version : Assign ScrollBar Class to Sprite


overbyte
03-14-2008, 04:39 PM
I know i'm missing something really obvious but is there a method to assign a ScrollBar to a Sprite?

I have a movie that builds a base sprite and then adds the timeline with titles, eras, and points and i want the scrollbar class to scroll that but i cannot find a way of marrying the timeline area and the scrollbar up.

here is my main class (with the inert scrollbar)


package com.receptacle.timeline
{
//package imports
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import fl.controls.ScrollBar;
import fl.controls.ScrollBarDirection;

public class TimelineApp extends Sprite
{
// class variable declarations
private var base:Sprite;
private var timelineArea:TimelineArea

// constructor
public function TimelineApp()
{
setVars();
setFullscreen();
addBaseSprite();
initialiseBackgroundElements();
initialiseMainTimeline();
initialiseEventNavigation();
initialiseTimelineScrollBar();
}

private function setVars()
{
base = new Sprite()
}

private function addBaseSprite():void
{
addChild(base);
}

private function setFullscreen():void
{
trace ("Fullscreen");
stage.displayState = StageDisplayState.FULL_SCREEN;
stage.scaleMode = StageScaleMode.NO_SCALE;
}

private function initialiseBackgroundElements():void
{
trace ("Background elements initialised");
var backgroundElements:BackgroundElements = new BackgroundElements();
base.addChild(backgroundElements);
}

private function initialiseMainTimeline():void
{
trace ("Main Timeline initialised");
timelineArea = new TimelineArea();
base.addChild(timelineArea);

// mask
var cp:CommonProperties = new CommonProperties();
var taPanelY:uint = cp.taTitleBarY;
var taPanelHeight:uint = cp.taTitleBarHeight + cp.taPanelHeight;

var taMask:Shape = new Shape();
taMask.graphics.beginFill(0xFF0000);
taMask.graphics.drawRect(0, taPanelY, 800, taPanelHeight);
base.addChild(taMask);
timelineArea.mask = taMask;
}

private function initialiseEventNavigation():void
{
trace ("Event navigation initialised");
}

private function initialiseTimelineScrollBar():void
{
trace ("Timeline scrollbar initialised");

var scrollBar:ScrollBar = new ScrollBar();
scrollBar.direction = ScrollBarDirection.HORIZONTAL;
scrollBar.x = 10;
scrollBar.y = 550;
scrollBar.setSize(280, 40);
addChild(scrollBar);


}
}
}

i'm sure it's something really blatant but i got nothin'

overbyte
03-15-2008, 03:42 PM
i've amended the code slightly which makes it react to the scrolling sprite (timelineArea) but it still doesn't actually scroll it along

amended code
private function initialiseTimelineScrollBar():void
{
trace ("Timeline scrollbar initialised");
var cp:CommonProperties = new CommonProperties();
var taPanelY:uint = cp.taTitleBarY;
var taPanelHeight:uint = cp.taTitleBarHeight + cp.taPanelHeight;

var scrollBar:ScrollBar = new ScrollBar();
scrollBar.direction = ScrollBarDirection.HORIZONTAL;
scrollBar.x = 10;
scrollBar.y = 550;
scrollBar.setSize(280, 40);
scrollBar.maxScrollPosition = timelineArea.width;
scrollBar.minScrollPosition = 0;
scrollBar.pageScrollSize = 20;
scrollBar.pageSize = stage.width;
addChild(scrollBar);
}
}


hope you guys can help :)

overbyte
03-17-2008, 10:31 AM
noone?

elnoctis
07-29-2008, 06:11 PM
Hi... I have the same problem, so I wonder if you could tell me what was wrong in your code.

I guess you need to declare scroll is targeting base sprite, don't you?