AS2 to AS3.0 ports are fun

A quick AS3.0 port of Lee’s AS2 scrolling thumbnail panel.

//stroke = instance name of mc on stage
var b:Rectangle = new Rectangle(stroke.x, stroke.y, stroke.width, stroke.height);

//panel = instance name of mc on stage
panel.addEventListener(MouseEvent.MOUSE_OVER, panelOver, false, 0, true); 

function panelOver(e:MouseEvent):void 
{	
	panel.addEventListener(Event.ENTER_FRAME, scrollPanel, false, 0, true); 
	panel.removeEventListener(MouseEvent.MOUSE_OVER, panelOver);
}

function scrollPanel(e:Event):void 
{
	//if mouse is outisde bounding box, b, then stop all scroll action		
	if(mouseX<b.left || mouseX>b.right || mouseY<b.top || mouseY>b.bottom) 	
	{
		panel.addEventListener(MouseEvent.MOUSE_OVER, panelOver, false, 0, true);		
		panel.removeEventListener(Event.ENTER_FRAME, scrollPanel);		
	}
	
	if(panel.x >= 89) panel.x = 89; //left bound	
	if(panel.x <= -751) panel.x = -751; //right bound 			
	
	var xdist:Number = mouseX - 250; //250 == stage.stageWidth/2 (if panel is centered on stage)  
	
	panel.x += Math.round(-xdist / 7);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s