OK, I looked for a couple of hours through Yahoo and google to see if anyone created a simple Scrubber script for controlling an externally loaded swfs, and I found none (only complex classes that use custom XML scripts or PHP).
This sample I made is for AS3 novice learners who find Classes intimidating. It may look long, but it really isn’t. The majority is just setting some initial values.
This script will load a single SWF and allow you to scrub the entire SWF with the CS4 slider component.
I have one little Bug with the slider indicator jumping back 18 frames when I release it. Other than that it works as expected. If anyone knows the solution to the strange bug, let me know.
[COLOR=#000000]Some Assumptions:[/COLOR]
You need to have a button on the stage called [COLOR=black]“newButton”[/COLOR]
Drag the slider component and label component to your library
import flash.events.MouseEvent;
import flash.text.TextFormat;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.Loader;
import fl.controls.Slider;
import fl.events.SliderEvent;
import fl.controls.Label;
import fl.containers.UILoader;
newButton.addEventListener(MouseEvent.CLICK, listButtonMouseClick);
function listButtonMouseClick(e:Event){
var capFile:String = "someSWF.swf";
var CAPreq:URLRequest = new URLRequest("assets/"+capFile);
var CAPloader:Loader = new Loader();
CAPloader.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
CAPloader.load(CAPreq);
function fileLoaded(event:Event)
{
addChild(CAPloader);
var CAPloader_mc:MovieClip = MovieClip(CAPloader.content);//This is needed in order to communicate to the swf
var sliderValue:uint = CAPloader_mc.currentFrame / CAPloader_mc.totalFrames *100;
var aSlider:Slider = new Slider();
aSlider.value = sliderValue;
aSlider.width = 200;
aSlider.snapInterval = 1;
aSlider.tickInterval = 20;
aSlider.maximum = 100;
aSlider.move(120, 330);
addChild(aSlider);
function enterFrameHandler(evt:Event)
{
sliderValue = CAPloader_mc.currentFrame / CAPloader_mc.totalFrames *100;
aSlider.value = sliderValue;
if (aSlider.value >=CAPloader_mc.totalFrames-1)
{
CAPloader_mc.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
}
var sliderLabel:Label = new Label();
sliderLabel.width = 120;
sliderLabel.text = 0 + " percent";
sliderLabel.move(170, 350);
addChild(sliderLabel);
aSlider.addEventListener(SliderEvent.THUMB_DRAG, DRAGHandler);
aSlider.addEventListener(SliderEvent.THUMB_RELEASE, RELEASEHandler);
function DRAGHandler(event:SliderEvent):void
{
sliderLabel.text = event.value + "%";
sliderValue = (event.value / 100) * CAPloader_mc.totalFrames ;
CAPloader_mc.gotoAndStop(sliderValue-1);
}
function RELEASEHandler(event:SliderEvent):void
{
CAPloader_mc.gotoAndPlay(sliderValue-1);//THe Indicator and sliderValue jump back 18 frames for some reason
CAPloader_mc.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
}
}
[COLOR=royalblue]Thanks and Enhance [/COLOR]
[COLOR=royalblue]Hioctane[/COLOR]