Hi everyone, once again I'm getting plagued by the dreaded Flash error: Cannot access a property or method.
I'm building a new video player and I need to send the total width of my progress bar(created in PlayerControls.as) to my VideoPlayer.as class. As well as control the width of the progress bar from an update function inside my VideoPlayer.as class.
I'm not able to get these values in my VideoPlayer class, I'm wondering if it has anything to do with the order of which I call these classes in my Document class:
Document Class
package {
// IMPORTS
public class TEN extends Global {
//private consts
//private vars
public function TEN():void {
if (stage) {
init();
} else {
addEventListener(Event.ADDED_TO_STAGE,init);
}
}
private function init(e:Event=null):void {
removeEventListener(Event.ADDED_TO_STAGE,init);
// Using the BulkLoader class to phrase XML
}
private function onBulkLoadComplete(e:Event):void {
trace("[BulkLoader] COMPLETE"+"\r");
Global.xml=loader.getXML("xmldata");
// I get XML values
// XML info goes into ARRAYS here
drawBackground();
drawVideo();
drawControls();
}
// Background.as
private function drawBackground():void {
trace("\r"+" drawBackground();");
trace("------------------------------");
bg=new Background ;
bg.drawBackground(globalWidth,globalHeight,firstTitle);
stage.addChild(bg);
}
// VideoDisplay.as
private function drawVideo():void {
trace("\r"+" drawVideo();");
trace("------------------------------");
vd=new VideoDisplay ;
vd.drawVideo(globalWidth,globalHeight,videoName,videoHDiff,limeLight);
vd.x=videoX;
vd.y=videoY;
stage.addChild(vd);
}
// PlayerControls.as
private function drawControls():void {
trace("\r"+" drawControls();");
trace("------------------------------");
pc=new PlayerControls ;
pc.drawControls(globalWidth,globalHeight,HEX,specialCheck,specialText,specialUrl);
pc.x=videoX;
pc.y=controlsY;
pc.addEventListener("onPlay",vd.playVideo);
pc.addEventListener("onPause",vd.pauseVideo);
stage.addChild(pc);
}
private function onBulkLoadProgress(e:BulkProgressEvent):void {
//trace(e.weightPercent);
}
}
}
PlayerControls.as
package src.ui
{
// IMPORTS
public class PlayerControls extends MovieClip
{
// private consts
// private vars
public var progressBar:MovieClip;
public var progressTotalW;
public function PlayerControls():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
}
public function drawControls(w, h, color, specialCheck, extraTxt, extraLink):void
{
// SET VALUES w,h,color, etc...
vd = new VideoDisplay(); // <-- VideoDisplay Class
// I create graphics
// I add graphics
createSpecialBtn(); // Create special button
}
// Create Special Button ·······································
public function createSpecialBtn():void
{
// other code
fullscreenCreate(btn_SpecialW); // Create FullScreen Button
}
// Create Fullscreen Button ·····································
public function fullscreenCreate(extraW):void
{
// other code
createSoundBtn(btn_Fullx); // Create Sound Button
}
// Create Sound Button ·····································
public function createSoundBtn(xSpacer):void
{
// other code
createTimeCounter(timeCountX); // Create Time Clock
}
// Create Time Count ·····································
public function createTimeCounter(spaceX):void
{
// other code
createGroove(); // Create progress bar background
}
// Create Groove Bar ············································
public function createGroove():void
{
// Here we go!
groove = new Groove();
groove.width = grooveW;
groove.x = grooveX;
groove.y = grooveY;
progressTotalW = grooveW;
//trace("grooveW = "+grooveW);
//trace("progressTotalW = "+progressTotalW);
vd.setProgressW(progressTotalW);
createProgress();
}
// Create Progress Bar ··········································
public function createProgress():void
{
progressBar = new ProgBar;
TweenLite.to(progressBar, .1, {tint:xmlColor});
progressBar.x = grooveX;
progressBar.y = grooveY;
progressBar.width = 1;
//trace("progressBar.x = "+progressBar.x);
//trace("progressBar.y = "+progressBar.y);
controls.addChild(groove);
controls.addChild(progressBar);
}
// BUTTON EVENTS here
}
}
VideoDisplay.as
package src.display
{
// IMPORTS
public class VideoDisplay extends PlayerControls
{
// Variables...
private var pc:PlayerControls;
public function VideoDisplay():void
{
this.addEventListener(Event.ADDED_TO_STAGE, stageListens);
}
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ NetStream Check
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
//case "NetConnection.Connect.Success": ... etc
}
}
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ Error Handling
private function asyncErrorHandler(event:AsyncErrorEvent):void {trace(event.text);}
private function onBWDone(...args):void {}
private function onXMPData(infoObject:Object):void {}
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ Declare MetaData
function getMetaData(client_ns) {
// Meta data
}
// ☼ --------------------------------------------------------------------------------- Connect to Stream
public function connectStream():void
{
// NetStream code
}
public function drawVideo(w, h, flvUrl, minusHeight, LL):void
{
sizeW = w;
sizeH = h;
flvSource = flvUrl;
appName = LL;
pc = new PlayerControls(); // <- PlayerControls.as
// RTMP - ns - nc CODE
// draw graphics
// Timer
tmrDisplay = new Timer(DISPLAY_DELAY);
tmrDisplay.addEventListener(TimerEvent.TIMER, updateDisplay); // <--
// addChilds
}
public function playVideo(e:CustomEvent = null):void
{
// play function
}
public function pauseVideo(e:CustomEvent = null):void
{
// pause function
}
// Getter & Setter
public function setProgressW(setMe):void
{
progressTotalW = setMe;
ajoyTest = setMe;
trace("Getter & Setter - progressTotalW = "+progressTotalW);
/*tmrDisplay = new Timer(DISPLAY_DELAY);
tmrDisplay.addEventListener(TimerEvent.TIMER, updateDisplay);*/
}
private function updateDisplay(e:TimerEvent):void
{
//trace("ns.time * 287 / videoDuration = "+(ns.time * 287 / videoDuration));
//pc.progressBar.width = ns.time * pc.progressTotalW / videoDuration;
//trace("ns.time = "+ns.time);
//trace("videoDuration = "+videoDuration);
trace("ajoyTest = "+ajoyTest);
trace("progressTotalW = "+progressTotalW);
}
// Other functions
}
}
^ for some reason I can't target the progressBar.width inside of PlayerControls.as
Any help or tips on this would be appreciated! UPDATE: Thanks for the insightful comments and answers everyone! Understanding how to properly instance a Class to be used by multiple Classes has just opened up my AS3 flexibility that much more :)