Hello Kirupa Community,
I have been developing a External SWF Player for about a week now and I am having major problems with the scrub bar portion of the project. I am posting here in hopes that someone will spare a few minutes and give me a hand.
-
-
- Goals of the Project - - -[LIST=1]
[]Load and External .swf time-lined movie into a container movieclip
[]Have a slider bar be able to control that external .swf
[*]The slider bar Thumb will move along the slider as the external .swf play[/LIST]So far I have the external .swf loading and being placed inside the demoContainer movie clip as well as the slider bar placed with the parameters of the external .swf.
- Goals of the Project - - -[LIST=1]
-
— Actionscript —
//==============================================================================================
//---- INTERACTIVE DEMOPLAYER v2.0 ----
//==============================================================================================
// import classes used throughout the demoPlayer actionscript
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.Sprite;
import flash.display.MovieClip;
import fl.controls.Slider;
import fl.events.SliderEvent;
//==============================================================================================
//---- EXTERNAL SWF PRE-LOADER AND PLACEMENT ----
//==============================================================================================
var targetRoot:MovieClip;
var request:URLRequest = new URLRequest("Template.swf");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
function loadProgress(event:ProgressEvent):void {
var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
trace("Loading: "+percentLoaded+"%");
}
function loadComplete(event:Event):void {
trace("Complete");
targetRoot = event.currentTarget.content;
scrubBar.maximum = targetRoot.totalFrames;
trace(scrubBar.maximum);
}
loader.load(request);
demoContainer.addChild(loader);
//==============================================================================================
//---- scrubBar Logic
//==============================================================================================
//set output text to 0
frameText.text = "You are currently on frame 0";
//instantiate slider
var scrubBar:Slider = new Slider();
//position slider
scrubBar.move(50,600);
// control if slider updates instantly or after mouse is released
scrubBar.liveDragging = false;
//set size of slider
scrubBar.setSize(875,0);
//set maximum value - the scrubBar.maximum value is set to the total number of frames of the external .swf movie
//scrubBar.maximum = 1000;
//set mininum value
scrubBar.minimum = 0;
//set tick position interval, you do not have to set this
scrubBar.tickInterval = 0;
//set the snap interval
scrubBar.snapInterval = 10;
//add slider inside the demoContainer mc
demoContainer.addChild(scrubBar);
// this is a listener that broadcasts evertime an event changes
scrubBar.addEventListener(SliderEvent.CHANGE, announceChange);
//gets called on change
function announceChange(event:SliderEvent):void {
//trace("Slider value is now: " + e.target.value);
targetRoot.gotoAndPlay(event.target.value);
frameText.text = "You are currently on frame " + event.target.value;
}
// this is a listener that broadcasts every time the thumb is pressed by the mouse
scrubBar.addEventListener(SliderEvent.THUMB_PRESS, stopDemo);
//gets called when the user does a mouse down on the thumb
function stopDemo(event:SliderEvent):void{
targetRoot.stop();
}
// this is a listener that broadcasts every time you enter the frame
stage.addEventListener(Event.ENTER_FRAME, swfTotalFrames);
//gets called every time you enter a frame
function swfTotalFrames(event:Event):void {
trace (targetRoot.currentFrame);
}
— Problems —
I am receiving an error…
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at demoPlayer_fla::MainTimeline/swfTotalFrames()
But I am still tracing out the proper information that I’m looking for, the external .swf’s total number of frames as well as the current frame that the swf is on while it is playing. How do you get rid of this error???
Also, how would you go about placing the Slider Thumb on the scrub bar according to what frame you are on in the external swf ???
I have attached my source files to this post in the link below. Any help would be much appreciated. Thank you everyone!
Source Files - http://www.jdhillen.com/uploads/kirupaPost.zip