Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-23-2010, 12:14 PM   PM User | #1
bucket
Regular Coder

 
Join Date: Sep 2008
Posts: 688
Thanks: 8
Thanked 17 Times in 16 Posts
bucket is infamous around these parts
Seperate AS file in zip.

Hey guys, I am wondering why is there a seperate as file in a zip I downloaded?

There are the files slider.as and slider.fla.

There is only one frame in the fla file and I was wondering if I can combine the fla and as file to make it work, since I will be combining it with another file.

This is the Slider.as file:
Code:
package {
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	public class Slider extends MovieClip {
		public static var SLIDE_ALIGN_LEFT:int = 1;
		public static var SLIDE_ALIGN_RIGHT:int = 2;
		public static var SLIDE_ALIGN_CENTER:int = 3;
		
		private var mSlideOffset:Number;
		private var mSlidebarOffsetLeft:Number;
		private var mSlidebarOffsetRight:Number;
		private var mSlidebarEffectiveWidth:Number;
		private var mSlidebarEffectiveX:Number;
		
		public function Slider():void {
			slide.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
			addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
			addEventListener(MouseEvent.MOUSE_OUT, mouseUpHandler);
			slidebar.addEventListener(MouseEvent.CLICK, mouseMoveHandler);
			
			// Assume alignment of left.
			mSlideOffset = 0;
			
			// Initialize the slidebar assuming no offsets.
			mSlidebarOffsetLeft = 0;
			mSlidebarOffsetRight = 0;
			updateSlidebarEffectiveValues();
		}
		
		public function get value():Number { 
			return (slide.x-mSlidebarEffectiveX+mSlideOffset)/mSlidebarEffectiveWidth;
		}
		
		public function set value(n:Number):void { 
			slide.x = mSlidebarEffectiveWidth * n - mSlideOffset + mSlidebarEffectiveX;
		}
		
		public function set slideAlign(alignment:int):void { 
			if(alignment == SLIDE_ALIGN_RIGHT)
				mSlideOffset = slide.width;
			else if(alignment == SLIDE_ALIGN_CENTER)
				mSlideOffset = slide.width/2;
			else
				mSlideOffset = 0;
		}
		
		public function set slidebarOffset(offset:Number):void { 
			mSlidebarOffsetLeft = offset; 
			mSlidebarOffsetRight = offset;
			updateSlidebarEffectiveValues();
		}
		
		public function set slidebarOffsetLeft(offset:Number):void { 
			mSlidebarOffsetLeft = offset; 
			updateSlidebarEffectiveValues();
		}
		
		public function set slidebarOffsetRight(offset:Number):void { 
			mSlidebarOffsetRight = offset; 
			updateSlidebarEffectiveValues();
		}
		
		private function updateSlidebarEffectiveValues():void {
			mSlidebarEffectiveWidth = slidebar.width-mSlidebarOffsetRight-mSlidebarOffsetLeft;
			mSlidebarEffectiveX = slidebar.x+mSlidebarOffsetLeft;
		}
		
		private function mouseDownHandler(event:MouseEvent):void {
			addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
		}
		
		private function mouseUpHandler(event:MouseEvent):void {
			trace(event);
			if(event.relatedObject != this && event.relatedObject != slide && event.relatedObject != slidebar)
				removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
		}
		
		private function mouseMoveHandler(event:MouseEvent):void {
			if(slidebar.mouseX < mSlidebarOffsetLeft)
				slide.x = slidebar.x+mSlidebarOffsetLeft-mSlideOffset;
			else if(slidebar.mouseX > slidebar.width-mSlidebarOffsetRight)
				slide.x = slidebar.x+slidebar.width-mSlidebarOffsetRight-mSlideOffset;
			else
				slide.x = this.mouseX - mSlideOffset;
		}
	}
}
When I try to copy that code, and paste it into the first frame of the Slider.fla to the action script its giving me an error that it cant be nested.

This is the fla file: http://uppit.com/v/AMTTEXHM


If someone can combine it to make it work off of one file named slider.fla would be great.
__________________
MY MSN: Sith717@Hotmail.com
PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
bucket is offline   Reply With Quote
Old 02-23-2010, 04:51 PM   PM User | #2
manny6574
New to the CF scene

 
Join Date: Feb 2010
Location: Guildford,UK
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
manny6574 is an unknown quantity at this point
Basically the seperate .as file is a class associated with the slider object in the library. To fix this simply put the .as in the same folder and test the movie. If you're worried about the stuff that apears on the bottom then don't. It means everything is working well(there are "trace" thingys in the class).
manny6574 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:43 PM.


Advertisement
Log in to turn off these ads.