hi guys

i'm a bit stuck with a project i'm working on. I have a timeline which all runs off a scrollbar similar to the one in the kirupa forum (http://www.kirupa.com/forum/showthread.php?t=245468 - amended to go horizontal and us Tweener to act a bit more smoothly)

at the moment, i have 2 sprites, 1 scrolls with the scrollbar and 1 doesn't. on the scrolling sprite i have several panels and the start of some ticks plus a mask for the non-scrolling textfield which is on the other sprite

everything works as it should with this, however - i'd like to push it a bit further so that the title (mainTitle) scrolls with the rest of the panels but when it hits the left hand side, it reparents to the non-scrolling sprite and stays there you can see an example of this at http://www.bbc.co.uk/history/ british/launch_tl_british.shtml - which i think is a really elegant solution to the problem of overlong panels, designed to take several points of interest

i've tried having everything on the scrollable sprite and moving the title backwards using a SliderEvent (custom event for the scrollbar) but the globalToLocal() method just gets really jumpy and doesn't seem to put the titles in the right place or return them correctly

this is my class:

CODE
package
{
        //package imports
        import flash.display.Sprite;
        
        //scrollbar imports
        import com.caurina.transitions.*;
        import flash.geom.*;
        import flash.events.*;
        import flash.text.TextFormat;
        import com.receptacle.utils.*;

        internal class TimelineArea extends Sprite
        {
                // class variable declarations
                private var cp:CommonProperties;
                private var taTitleBarY;
                private var taPanelY:uint;
                private var taPanelHeight:uint
                private var scrollableBase:Sprite;
                private var scrollbar:Scrollbar
                private var stage_width:uint;
                private var stage_height:uint;

                private var panelY:uint;
                private var panelColour:uint;
                private var taTitleBarHeight:uint;
                private var nonScrollableBase:Sprite;
                private var commonGrey:uint;
                private var subheadingFont:String;
                private var headingFont:String;

                // constructor
                public function TimelineArea():void
                {
                        setVars();
                        addTicks();
                        addPanels();
                        addPeriodBars();
                        addImageLandmark();
                        initialiseTimelineScrollBar();
                }
                
                private function setVars()
                {
                        scrollbar = new Scrollbar();
                        cp = new CommonProperties();
                        stage_width              = cp.stage_width;
                        stage_height     = cp.stage_height;
                        taTitleBarHeight = cp.taTitleBarHeight;
                        taTitleBarY              = cp.taTitleBarY;
                        taPanelY         = cp.taPanelY;
                        taPanelHeight    = cp.taPanelHeight;
                        commonGrey       = cp.tickColour;
                        headingFont      = cp.headingFont;
                        subheadingFont   = cp.subheadingFont;
                        
                        scrollbar.x     = 16;
                        scrollbar.y     = 550-cp.titleBarHeight;
                        
                        scrollableBase = new Sprite();
                        nonScrollableBase = new Sprite();
                        scrollableBase.y = 0;
                        
                        addChild(scrollableBase);
                        addChild(nonScrollableBase);
                }
                
                private function addPanels():void
                {
                        trace ("Background panels added");
                        
createPanel(0, 1000, 0xB60000, "Prehistory", "c. 1.7 million - 4000 B.C.E."); createPanel(1000, 2000, 0xB65B00, "Early Civilisations", "c. 1.7 million - 4000 B.C.E."); createPanel(3000, 2000, 0x123456, "Sumfink Else", "c. 1.7 million - 4000 B.C.E.");
                        
                        
                }
                
private function createPanel(panelX:Number, panelWidth:int, panelColour:uint, pTitle:String, date:String):void
                {
// SimpleRectangle class (rColour:uint, rOutlineColour:uint, rX:Number, rY:Number, rWidth:uint, rHeight:uint) var mainTitlePanel:SimpleRectangle = new SimpleRectangle(0xFFFFFF, panelColour, panelX, 0, panelWidth, taTitleBarHeight);
                        scrollableBase.addChild(mainTitlePanel);
                        
// SimpleTextField class (tfColour:uint, tfSize:uint, tfFont:String, tfX:Number, tfY:Number, tfWidth:uint, tfHeight:uint, tfCopy:String, tfAutoSize:Boolean = false) var mainTitle:SimpleTextField = new SimpleTextField(panelColour, 36, headingFont, 5, 5, panelWidth, 5, pTitle, true);
                        nonScrollableBase.addChild(mainTitle);
                        
                        // this is to append the date with a space before
                        mainTitle.text += " ";
                        mainTitle.text += date;
                        // set format for date
                        var stf:TextFormat = new TextFormat();
                        stf.font                                        = 
subheadingFont;
                        stf.color                                       = 
commonGrey;
                        stf.size                                        = 14;
                        var titleCurrentLength:uint = pTitle.length+1;
                        var dateLength:uint         = mainTitle.length;
                        mainTitle.setTextFormat(stf, titleCurrentLength, 
dateLength);
                        
                        var nonScrollableBaseMask:Sprite = new Sprite();
                        nonScrollableBaseMask.graphics.beginFill(0x0000000);
nonScrollableBaseMask.graphics.drawRect(panelX, 0, panelWidth, taTitleBarHeight);
                        scrollableBase.addChild(nonScrollableBaseMask);
                        
                        mainTitle.mask = nonScrollableBaseMask;
                        
var panel:SimpleRectangle = new SimpleRectangle(panelColour, panelColour, panelX, taTitleBarHeight, panelWidth, taPanelHeight);
                        scrollableBase.addChild(panel);

                }
                
                private function addTicks():void
                {
                        // will be put on a loop in the final class
                        trace ("Adding Ticks");
                        var tick1:ShortTick = new ShortTick(5, -1500);
                        var tick2:ShortTick = new ShortTick(10, -1000);
                        var tick3:ShortTick = new ShortTick(15, -500);
                        var tick4:ShortTick = new ShortTick(20, 0);
                        var tick5:LongTick  = new LongTick (25, 500);
                        scrollableBase.addChild(tick1);
                        scrollableBase.addChild(tick2);
                        scrollableBase.addChild(tick3);
                        scrollableBase.addChild(tick4);
                        scrollableBase.addChild(tick5);
                }
                
                private function addPeriodBars():void
                {
                        trace ("Period bars added");
                }

                private function addImageLandmark():void
                {
                        trace ("Image landmarks added");
                }
                
                private function initialiseTimelineScrollBar():void
                {
                        trace ("Timeline scrollbar initialised");
                        
var scroll_rect:Rectangle = new Rectangle( 0, 0, stage_width, taPanelHeight+taTitleBarHeight+30 ); var sc:ScrollContent = new ScrollContent( scrollableBase, scrollbar, scroll_rect );
                        
                        addChild( scrollbar );
                }
        }
}
/CODE

here is my first attempt to move everything back into place. Note this was an older version of the class so not entirely correct any more but it's a look at my thought process

//              private function resetTitlePos(e:SliderEvent):void
//              {
//                      var globalPoint:Point = new Point(5, panelY);
//                      var localPoint:Point = 
scrollableBase.globalToLocal(globalPoint);
//                      if (localPoint.x > 5)
//                      {
//                              mainTitle.x = localPoint.x+5;
//                      }
//              }

as this didn't work, i started trying to reparent the mainTitle:SimpleTextField to the nonscrollableBase but with little success as i couldn't access the panel's parameters within the Event

am i going about this in the wrong way?

thanks
a





Allandt Bik-Elliott
thefieldcomic.com
e [EMAIL PROTECTED]

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to