Forums: Flash:

 

Flash getting errors in class that isn't even being used

first
 

Big Ern Flash getting errors in class that isn't even being used

Confused? Me too.

Say I have this in a class:

		
private var _image:String;
public function set image( value:String ):void
{
this._image = value;
checkValues();
}

private var _vid:String;
public function set vid( value:String ):void
{
this._vid = value;
checkValues();
}

private var _pdf:String;
public function set pdf( value:String ):void
{
this._pdf = value;
checkValues();
}



private var _loadMC:Sprite;
public function set loadMC( value:Sprite ):void
{
this._loadMC = value;
checkValues();
}

private function checkValues():void
{
if( _image && _loadMC)
{
var _imageLoad:ImageLoad = new ImageLoad();
_imageLoad.image = _image;
_imageLoad.loadMC = _loadMC;
}
else if( _vid && _loadMC)
{
var _vidLoad:VidLoad = new VidLoad();
_vidLoad.vid = _vid;
_vidLoad.loadMC = _loadMC;
}
else if( _pdf && _loadMC)
{
var _pdfLoad: PdfLoad = new PdfLoad();
_pdfLoad.pdf = _pdf;
_pdfLoad.loadMC = _loadMC;
}
else
{
trace("defining properties");
}

}


From the document class I send _image and _imageMC to the above class and I get the error:

"VidLoad.as, Line 76 -- 1046: Type was not found or was not a compile-time constant: VideoEvent."

but I shouldn't have gotten that anyway as I didn't send _vid in the first place... why would it worry about anything in VidLoad.as when it doesn't even get inside that else if?!

I know it never gets in because "trace("loading video");" is never triggered.

 

DontBogartMe

it's a compile time error, so it doesn't worry about whether or not that IF block would ever happen at runtime, it just tries to compile your VidLoad class and finds an error in it.

You are getting this error when you try to publish the FLA right?

 

Big Ern

you are right again. Duh.

I understand my problem now, but that means I have a different issue.

There actually isn't an error in VidLoad.as, the reason it says there is is because I am doing this in it:

import fl.video.FLVPlayback;

and because this particular fla does not load any videos (other ones in the series do), I haven't loaded the FLVPlayback component into the library.

If I drag an instance of FLVPlayback onto the stage and delete it, everything works, however I don't want to do that if I'm not going to use it. Is there any way to get around this?

 

DontBogartMe

well I think this:
Type was not found or was not a compile-time constant: VideoEvent.
is telling you to import the VideoEvent class. Do that and see if it helps.

 

Big Ern

Sorry, I should've mentioned I'm doing that already. I'm importing all three of these:

import fl.video.FLVPlayback;
import fl.video.VideoScaleMode;
import fl.video.VideoEvent;

I'd include the code for the whole VidLoad class, but I know that it is working because when I run one of the other flas that use it and have the FLVPlayback component in the library, everything is hunky dorey.

 

DontBogartMe

what's the structure of your app? What are the FLAs and what are their document classes?

I'm confused about this

and because this particular fla does not load any videos (other ones in the series do), I haven't loaded the FLVPlayback component into the library.

sounds fishy to me smile

 

Big Ern

haha, you know me too well. It's probably (as usual) a shit way to do it, but:

I have a series of Flas that dynamically create buttons that can load either a html page, a swf, a pdf or a video into a movieclip on the stage.

1. The document class for each fla loads an xml doc and sends xml data to a "ButtonBuilder" class.

2. The ButtonBuilder class creates a new "StepButton" class for EACH button (usually 5 or 6) and sends two properties to it; the path to the media and the movieclip the media is to be loaded into. (stepButton._vid, stepButton._image, stepButton._pdf etc etc). Some flas load pdfs, some load pdfs and images, some load images and videos or all three.

3. Each Stepbutton class determines which class to create based on the NAME of the property sent and creates a new class specific to the media it's trying to load. If _vid is set, it creates a new instance of "VidLoad", if _image is set, "ImageLoad" is created and so on. It determines which class to create with if... else statements as above in my original post.

Like I said before, the only part that breaks is when I use these same classes and I don't have the FLVPlayer loaded into the library of the fla. As you figured out before, the flaw lies in the fact that it compiles before it hits the if... else statement and finds an error when the FLVPlayer component is missing.

What that means is that I have to either (somehow) get it to ignore VidLoad at compile time until it determines whether there is video to load or not, or I have to load the FLVPlayer into the library of every fla that uses ButtonBuilder or StepButton even if that particular one doesn't load any video.

Does any of that convoluted gobbeldygook make any sense? big grin

 

Big Ern

btw -- I updated my original post to add the pdf bit to you give a better look at how it determines which type of media it should load.

 

Big Ern

Also, Dan if it's more pain than it's worth to help a dumbass like me, don't worry about it. I know I can't describe my problems for shit. big grin

Worse comes to worse, I'll just drag the FLVPlayback component to the stage on every fla that uses those classes.

 

baron ruhstoff

If I understand it right, you have a container swf into which you are loading other swfs that may or may not contain instances of the FLVPlayback component. You want to limit the size of the container swf by not including the component, but you need access to the related methods in the child swfs, right?

One thing you can do is create proxy methods in the children that allow them to act as sort of an interface between the video player and the container swf:

class Child {
private var flvplayback:FLVPlayback;
// gives access to any containers without requiring them to know about FLVPlayback
public function playVideo():void{
flvplayback.play();
}
}


A less strict, but perhaps more convenient approach, is to hack it out:
class Container {
// assumes that a child of unknown type has a method called "play"
private var child:*;
private function whatever():void{
child["play"];
}
}


Then again, if all you want to do is have Container respond to a VideoEvent without having to import everything, you could get away with simply listening for the event type's string rather than the constant:
class Container {
private function init():void{
// assumes that the constant is "playbackBegin" - check VideoEvent source for the real value
child.addEventListener("playbackBegin", onPlaybackBegin);
}
}


BUT I think I may have misinterpreted what you're aiming for. smile

 

DontBogartMe

Originally posted by: Big Ern
Also, Dan if it's more pain than it's worth to help a dumbass like me, don't worry about it. I know I can't describe my problems for shit. big grin

ah hush you fool smile I like helping if I can. It's often good practice too. And god knows I've had plenty of help on forums myself, and will ask for it again, so I'm also just doing my bit.


Baron - I think what he's after here is to create a number of self contained SWFs that are all based off the same document class. They then each run on their own, some loading HTML, some loading PDFs, Images and some loading Videos. Or a combo of those.

The problem seems to be that your VidLoad class only works when there's an FLVPlayback component in the library - you need to remove that dependance.

To be honest I don't know why you're having this problem. The help docs say that you can do it either way, by having it in the library or by importing it.
livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/video/FLVPlayback.html

ok so I've now done a little test and it doesn't work if you don't have the FLVPlayback component in your library.

so what can you do? You could simply bite the bullet and always have it in your library whether you need it or not.

Or you could create an FLA that contains the FLVPlayback component and some code to set it up and play a video. Your other main movie would then load in that SWF and have it play the video - therefore removing the need to have the FLVPlayback comp in the main FLA's library. It sounds like a pain in the arse but it'll probably only take 15 mins.

 

baron ruhstoff

Ahh. Got it.

Originally posted by: DontBogartMe
Or you could create an FLA that contains the FLVPlayback component and some code to set it up and play a video. Your other main movie would then load in that SWF and have it play the video - therefore removing the need to have the FLVPlayback comp in the main FLA's library. It sounds like a pain in the arse but it'll probably only take 15 mins.


conifers

 

Big Ern

Originally posted by: DontBogartMe
The problem seems to be that your VidLoad class only works when there's an FLVPlayback component in the library - you need to remove that dependance.

so what can you do? You could simply bite the bullet and always have it in your library whether you need it or not.

Or you could create an FLA that contains the FLVPlayback component and some code to set it up and play a video. Your other main movie would then load in that SWF and have it play the video - therefore removing the need to have the FLVPlayback comp in the main FLA's library. It sounds like a pain in the arse but it'll probably only take 15 mins.


hmmm, that's an interesting idea, I'll try that.

Thanks for the help, boys.



 
first
 

Forums: Flash: Flash getting errors in class that isn't even being used

 
New Post
 
You must be logged in to post