# AS3:Merging Class-Based with Timeline Code

**URL:** <https://forum.kirupa.com/t/as3-merging-class-based-with-timeline-code/294699>\
**Category:** flash\
**Created:** [August 18, 2009, 6:52pm UTC](https://forum.kirupa.com/t/as3-merging-class-based-with-timeline-code/294699 "2009-08-18T18:52:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrwizzer](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@mrwizzer](https://forum.kirupa.com/u/mrwizzer)\
**Post date:** [August 18, 2009, 6:52pm UTC](https://forum.kirupa.com/t/as3-merging-class-based-with-timeline-code/294699/1 "2009-08-18T18:52:54Z")

</div>

My frustration with AS3 is mounting. This whole class-based approach is pretty confusing, but doubly confusing when you see so much time-line based AS3, and need to merge code snippets from one into another.

Is there a clear method of doing this that someone can share?

Scenario: I’ve created a class-based video player (has all the “import.flash.media” and the “public class AS3videoPlayer extends MovieClip” stuff, etc. that’s such a pain, but I muddled through it and it works fine).

But now I need to add a scrub bar and a volume control, which I’ve created before but in timeline-based AS3 (so there’s no “import.flash.media” and there’s no “private class etc.” stuff.

I’ve tried inserting the volume control stuff into the class-based AS3 file, but I get nothing but endless error messages.

Can someone explain what I need to do to mix the two AS3 types? (Why does this need to be so darn confusing?)

Thanks.

Here’s the timeline-based code I’m trying to insert into a Class-based file:

```auto
//Code that handles the sound volume
var vol:SoundTransform=SoundMixer.soundTransform;
var ratio_volume:Number;
var trackBounds:Rectangle=track_mc.getBounds(track_mc);
var xPos:Number=trackBounds.x+6;
var yPos:Number=trackBounds.y+5;
var widthPos:Number=trackBounds.width-track_mc.slider_mc.width;
var heightPos:Number=0;
var bounds:Rectangle=new Rectangle(xPos,yPos,widthPos,heightPos);
track_mc.slider_mc.x=widthPos;
track_mc.mouseEnabled=false;
track_mc.slider_mc.buttonMode=true;

track_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN,dragSlider);
stage.addEventListener(MouseEvent.MOUSE_UP,stopSlider);

function dragSlider(event:MouseEvent):void {
	event.target.startDrag(true,bounds);
	addEventListener(Event.ENTER_FRAME,setVolume);
}

function stopSlider(event:MouseEvent):void {
	track_mc.slider_mc.stopDrag();
	removeEventListener(Event.ENTER_FRAME,setVolume);
}
function setVolume(event:Event):void {
	ratio_volume=track_mc.slider_mc.x/widthPos;
	vol.volume=ratio_volume;
	SoundMixer.soundTransform=vol;
	trace("vol.volume is: " + vol.volume);
	trace("track_mc.slider_mc.x is: " +track_mc.slider_mc.x);
	trace("widthPos is: " + widthPos);

	if (vol.volume<0.1) {
		vol.volume=0;
		SoundMixer.soundTransform=vol;
		muteIcon.x=112.4;
	} else {
		muteIcon.x=242;
	}

}

```
