How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask ATLPROG Your Own Question

ATLPROG
ATLPROG, Computer Software Engineer
Category: Programming
Satisfied Customers: 7260
Experience:  MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
44910485
Type Your Programming Question Here...
ATLPROG is online now

flash slider in actionscript 3

Customer Question

, I'm building a flash slider in actionscript 3 using a external slider class that I found on the internet. I'm pulling in the position of the slider into a dynmaic text filed whne the slider first appears but I need the value in the dynamic text field to update everytime the the mouse is down and the cursor moves the position.I then need that number to be saved in a variable so that I can use it again later. I have uploaded the flash files here: http://we.tl/evfQHjmYow

The class that I have used is below:


package com.reintroducing.ui
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.geom.Rectangle;
import flash.utils.Timer;
import flash.utils.getQualifiedClassName;


/**
* The SliderUI is a class that allows you to quickly create sliders with tracks without the need to use components.
* There is a "percent" and a "currentValue" property that you can tap into to see what position the slider is at on the track.
* </ p>
* Please note that if you are using the SliderUI on the "y" axis your track's registration point needs to be on the
* bottom (NOT the top) and the slider will go up to raise the value and down to lower it. If you do not pay attention
* to this your slider will be "broken".
*
* @author Matt Przybylski [http://www.reintroducing.com]
* @version 1.0
*/
public class SliderUI
{
//- PRIVATE & PROTECTED VARIABLES -------------------------------------------------------------------------


private var _stage:Stage;
private var _track:Sprite;
private var _slider:Sprite;
private var _timer:Timer;
private var _percent:Number;
private var _lowVal:Number;
private var _highVal:Number;
private var _startVal:Number;
private var _currentVal:Number;
private var _range:Number;
private var _axis:String;
private var _changeProp:String;

//- PUBLIC & INTERNAL VARIABLES ---------------------------------------------------------------------------

//- CONSTRUCTOR -------------------------------------------------------------------------------------------

/**
* Creates an instance of the SliderUI with the given parameters. If the $startVal parameter is set to something
* higher than the $highVal or lower than the $lowVal parameter, the $startVal parameter is reset to one of those two values.
*
* @param $stage The stage that the track and slider are sitting on
* @param $axis The axis that the slider will be used on
* @param $track The track to be used slider
* @param $slider The object that will function as the slider
* @param $lowVal A number representing the low value of the slider
* @param $highVal A number representing the high value of the slider
* @param $startVal A number representing the value the slider should start at (default: 0)
*
* @return void
*/
public function SliderUI($stage:Stage, $axis:String, $track:Sprite, $slider:Sprite, $lowVal:Number, $highVal:Number, $startVal:Number = 0):void
{
this._stage = $stage;
this._axis = $axis;
this._track = $track;
this._slider = $slider;
this._lowVal = $lowVal;
this._highVal = $highVal;
this._startVal = $startVal;

this._changeProp = (this._axis == "x") ? "width" : "height";
this._range = (Math.abs(this._lowVal) + this._highVal);
this._slider.buttonMode = true;
this._timer = new Timer(10);

if (this._startVal < this._lowVal) this._startVal = this._lowVal;
if (this._startVal > this._highVal) this._startVal = this._highVal;

if (this._startVal < 0)
{
this._percent = (Math.abs(this._lowVal + Math.abs(this._startVal)) / this._range);
}
else
{
this._percent = (Math.abs(this._lowVal - this._startVal) / this._range);
}

this._currentVal = (this._lowVal + (this._range * this._percent));

if (this._axis == "x")
{
this._slider[this._axis] = (this._track[this._axis] + (this._percent * this._track[this._changeProp]));
}
else
{
this._slider[this._axis] = (this._track[this._axis] - (this._percent * this._track[this._changeProp]));
}

this.initEvents();
}

//- PRIVATE & PROTECTED METHODS ---------------------------------------------------------------------------

/**
* Initializes the slider and timer events.
*/
private function initEvents():void
{
this._slider.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
this._slider.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
this._timer.addEventListener(TimerEvent.TIMER, updateInfo);
}

//- PUBLIC & INTERNAL METHODS -----------------------------------------------------------------------------

/**
* Enables the controls of the SliderUI.
*
* @return void
*/
public function enable():void
{
this.initEvents();
}

/**
* Disables the controls of the SliderUI.
*
* @return void
*/
public function disable():void
{
this._slider.removeEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
this._slider.removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
this._timer.removeEventListener(TimerEvent.TIMER, updateInfo);
}

/**
* Cleans up the SliderUI collection.
*
* @return void
*/
public function destroy():void
{
this.disable();

this._timer = null;
}

//- EVENT HANDLERS ----------------------------------------------------------------------------------------

/**
* Starts the dragging of the slider and starts the timer to dispatch percentage.
*/
private function handleMouseDown($evt:MouseEvent):void
{
if (this._axis == "x")
{
this._slider.startDrag(false, new Rectangle(this._track.x, this._slider.y, this._track.width, 0));
}
else
{
this._slider.startDrag(false, new Rectangle(this._slider.x, this._track.y, 0, -this._track.height));
}

this._timer.start();

this._stage.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
}

/**
* Stops the slider dragging and timer.
*/
private function handleMouseUp($evt:MouseEvent):void
{
this._slider.stopDrag();
this._timer.reset();

this._stage.removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
}

/**
* Updates the info of the slider's position.
*/
private function updateInfo($evt:TimerEvent):void
{
this._percent = Math.abs((this._slider[this._axis] - this._track[this._axis]) / this._track[this._changeProp]);
this._currentVal = (this._lowVal + (this._range * this._percent));
}


//- GETTERS & SETTERS -------------------------------------------------------------------------------------

/**
* Returns the percentage of the slider's position on the track, between 0 and 1.
*
* @return Number
*/
public function get percent():Number
{
return this._percent;
}

/**
* Returns the current value of the slider's position on the track.
*
* @return Number
*/
public function get currentValue():Number
{
return this._currentVal;
}

//- HELPERS -----------------------------------------------------------------------------------------------

public function toString():String
{
return getQualifiedClassName(this);
}

//- END CLASS ---------------------------------------------------------------------------------------------
}
}

Here is the code that I have in the flash file that contains the slider itself:


//Slider
import com.reintroducing.ui.SliderUI;


var sui:SliderUI = new SliderUI(stage, "x", track_mc, slider_mc, 0, 100, 50);
trace("FIRST PERCENT: " + sui.percent + " & VALUE: " + sui.currentValue);


//Read position value
var currentpercent01;
currentpercent01 = sui.currentValue;
trace (currentpercent01);


//Put percent value in box
currentpercent01text.text = String(currentpercent01 + "%");
stop();

Submitted: 1 year ago.
Category: Programming

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer
< Previous | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C.
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C.
 
 
 

Meet The Experts:

 
 
 
  • ATLPROG

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7260
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
< Last | Next >
  • http://ww2.justanswer.com/uploads/SP/spatlanta2010/2011-6-23_12450_photo.64x64.gif ATLPROG's Avatar

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7260
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Computer Software Engineer

    Satisfied Customers:

    5514
    Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
  • http://ww2.justanswer.com/uploads/lifesaver333/2010-10-17_191349_ls.jpeg lifesaver's Avatar

    lifesaver

    Computer Software Engineer

    Satisfied Customers:

    936
    Several years of intensive programming and application development experience in various platforms.
  • http://ww2.justanswer.com/uploads/EH/ehabtutor/2012-8-2_202016_1.64x64.jpg ehabtutor's Avatar

    ehabtutor

    Computer Software Engineer

    Satisfied Customers:

    766
    Bachelor of computer science, 5+ years experience in software development, software company owner
  • http://ww2.justanswer.com/uploads/eljonis/2010-01-06_130406_eljon2.jpg Eljon's Avatar

    Eljon

    Consultant

    Satisfied Customers:

    558
    Founder of StockCanvas.com
  • http://ww2.justanswer.com/uploads/FA/fael/2011-1-15_104041_profile500x500.64x64.jpg Rafael Martins's Avatar

    Rafael Martins

    Computer Software Engineer

    Satisfied Customers:

    446
    Desktop, Mobile and Web Developer. 7+ years of experience. Creative solutions provider.
  • http://ww2.justanswer.com/uploads/CH/chutz747/2011-11-6_14231_me.64x64.jpg The-PC-Guy's Avatar

    The-PC-Guy

    Software Engineer

    Satisfied Customers:

    320
    Extensive Knowledge in PHP, MYSQL, CSS & Javascript