replaced the Scrollbar method with this

[CODE]
        // executes when the up arrow is pressed
        protected function arrowPressed( e:MouseEvent ):void
        {
                        trace (e.target.name);
            var dir:int = (e.target == left_arrow) ? -1 : 1;
                        scrollTarget(dir);
        }
                
                public function leftBumperPressed (e:MouseEvent):void
                {
                        var dir:int = -1;
                        scrollTarget(dir);
                }
                
                public function rightBumperPressed (e:MouseEvent):void
                {
                        var dir:int = 1;
                        scrollTarget(dir);
                }
                
                private function scrollTarget (dir:int)
                {
                        var total:Number = slider.percent + (dir * scrollSpeed);
Tweener.addTween(slider,{percent:total, time:0.5}); // Tweener tween added to add friction to arrow presses - God bless Zeh and chums!
                }
[/CODE]

a


On 25 Mar 2008, at 12:29, Allandt Bik-Elliott (Receptacle) wrote:

Hi guys

quick question really.

I have a Scrollbar class with a public method, arrowPressed (e:MouseEvent), that i'm trying to call from another class, TimelineArea(), using objects with the same name with the lines:

left_arrow.addEventListener( MouseEvent.MOUSE_DOWN, scrollbar.arrowPressed ); right_arrow.addEventListener( MouseEvent.MOUSE_DOWN, scrollbar.arrowPressed );
// note scrollbar is an instance of the Scrollbar class

the method in the Scrollbar class is as follows:

public function arrowPressed( e:MouseEvent ):void
{
        var dir:int = (e.target == left_arrow) ? -1 : 1;
        var total:Number = slider.percent + (dir * scrollSpeed);
Tweener.addTween(slider,{percent:total, time:0.5}); // Tweener tween added to add friction to arrow presses - God bless Zeh and chums!
}


The result of this is that both left_arrow and right_arrow in the TimelineArea class give a (e.target == left_arrow) = false result and only move the timeline forward whereas the left_arrow and right_arrow within the Scrollbar class give the correct result: right_arrow = false (moves the timeline +1), left_arrow = true (moves the timeline -1)

why would using the public method externally pass a different result to using it internally, please?

I've included both classes below for context

thanks for your time
a



Scrollbar Class
[CODE]
package
{
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import com.caurina.transitions.*;

    public class Scrollbar extends Sprite
    {
        // elements
        protected var slider:Slider;
        protected var left_arrow:Sprite;
        protected var right_arrow:Sprite;

        protected var scrollSpeed:Number = .02;

        // read/write percentage value relates directly to the slider
public function get percent():Number { return slider.percent; } public function set percent( p:Number ):void { slider.percent = p; }

        public function Scrollbar()
        {
            createElements();
        }

        // executes when the up arrow is pressed
        public function arrowPressed( e:MouseEvent ):void
        {
                        var dir:int = (e.target == left_arrow) ? -1 : 1;
                        var total:Number = slider.percent + (dir * scrollSpeed);
Tweener.addTween(slider,{percent:total, time:0.5}); // Tweener tween added to add friction to arrow presses - God bless Zeh and chums!
        }

        protected function createElements():void
        {
            slider = new Slider();

            left_arrow = new Sprite();
            left_arrow.graphics.beginFill( 0x999999, 1 );
                        left_arrow.graphics.moveTo(20,0);
            left_arrow.graphics.lineTo(20,40);
                        left_arrow.graphics.lineTo(10,40);
                        left_arrow.graphics.curveTo(0,40,0,30);
                        left_arrow.graphics.lineTo(0,10);
                        left_arrow.graphics.curveTo(0,0,10,0);
                        left_arrow.graphics.lineTo(20,0);
            left_arrow.graphics.endFill();

            right_arrow = new Sprite();
            right_arrow.graphics.beginFill( 0x999999, 1 );
                        right_arrow.graphics.lineTo(10,0);
                        right_arrow.graphics.curveTo(20,0,20,10);
                        right_arrow.graphics.lineTo(20,30);
                        right_arrow.graphics.curveTo(20,40,10,40);
                        right_arrow.graphics.lineTo(0,40);
                        right_arrow.graphics.lineTo(0,0);
            right_arrow.graphics.endFill();

            slider.x = left_arrow.width;
            right_arrow.x = slider.x + slider.width;

left_arrow.addEventListener( MouseEvent.MOUSE_DOWN, arrowPressed ); right_arrow.addEventListener( MouseEvent.MOUSE_DOWN, arrowPressed );

            addChild( slider );
            addChild( left_arrow );
            addChild( right_arrow );
        }

public override function addEventListener( type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false ):void
        {
            if ( type === SliderEvent.CHANGE )
            {
slider.addEventListener( SliderEvent.CHANGE, listener, useCapture, priority, useWeakReference );
                return;
            }
super.addEventListener( type, listener, useCapture, priority, useWeakReference );
        }
public override function removeEventListener( type:String, listener:Function, useCapture:Boolean=false ):void
        {
            if ( type === SliderEvent.CHANGE )
            {
slider.removeEventListener( SliderEvent.CHANGE, listener, useCapture );
                return;
            }
            super.removeEventListener( type, listener, useCapture );
        }
    }
}
[/CODE]

TimelineArea Class (cut down for readability and relevance)
[CODE]
package
{
        //package imports
        import flash.display.Sprite;
        
        //scrollbar imports
        import com.caurina.transitions.*;
        import flash.geom.*;
        import flash.events.*;
import com.receptacle.utils.*; // includes SimpleRectangle and SimpleTextField

        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 yearDistance:uint;
                private var startYear:int;
                private var endYear:int;
                private var yearDiv: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();
                        initialiseTimelineScrollBar();
                        addTimelineAreaNavigation();
                }
                
                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;
                        yearDistance     = cp.yearDistance;
                        startYear        = cp.startYear;
                        endYear          = cp.endYear;
                        yearDiv          = cp.yearDiv;

                        scrollbar.x     = 16;
                        scrollbar.y     = 550-cp.titleBarHeight;
                        scrollableBase = new Sprite();
                        nonScrollableBase = new Sprite();
                        scrollableBase.y = 0;
                        
                        addChild(scrollableBase);
                        addChild(nonScrollableBase);
                }
                
                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 );
                }

                private function addTimelineAreaNavigation():void
                {
var left_arrow:SimpleRectangle = new SimpleRectangle(0x000000, 0x000000, 0, 0, stage_width/3, taPanelHeight + taTitleBarHeight); var right_arrow:SimpleRectangle = new SimpleRectangle(0x000000, 0x000000, (stage_width/3)*2, 0, stage_width/3, taPanelHeight + taTitleBarHeight);
                        
                        left_arrow.alpha = 0;
                        right_arrow.alpha = 0;
                        
left_arrow.addEventListener( MouseEvent.MOUSE_DOWN, scrollbar.arrowPressed ); right_arrow.addEventListener( MouseEvent.MOUSE_DOWN, scrollbar.arrowPressed );
                        
                        addChild(left_arrow);
                        addChild(right_arrow);
                }
        }
}
[/CODE]


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



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

Reply via email to