PDA

View Full Version : Problems calling Public Functions


tsquini
04-07-2008, 09:57 PM
I am having an issue calling public functions between classes.
I have 2 classes: FLVPlaybackCaptioningExample and DynamicButton.
In the DynamicButton class I am defining all of the mouseEvents on the dynamic buttons. On MouseEvent.CLICK I call a function from FLVPlaybackCaptioningExample that should .seekSeconds() to the FLV
player on frame 1 of the timeline.

To create the buttons I am loading a MovieClip from the Library
and using the class "videoCap.DynamicButton"

When I compile the movie it gives me an error:
1180: Call to a possibly undefined method seekToMovie.

package videoCap{
import fl.video.CaptionChangeEvent;
import fl.video.FLVPlayback;
import fl.video.FLVPlaybackCaptioning;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.system.*;

public class FLVPlaybackCaptioningExample extends MovieClip {

private var videoPath:String = "TESTVid.flv";
private var captioningPath:String = "caption.xml";

public function FLVPlaybackCaptioningExample() {
player.source = videoPath;
captioning.flvPlayback = player;
captioning.source = captioningPath;
captioning.autoLayout = false;
captioning.addEventListener(CaptionChangeEvent.CAP TION_CHANGE, onCaptionChange);
writeNav();
}


//--------------------------//
I can't seem to call this function
public function seekToMovie(mySeekNum:Number):Number{
player.seekSeconds(mySeekNum);
}
//--------------------------//



private function onCaptionChange(e:CaptionChangeEvent):void {
var tf:* = e.target.captionTarget;
var player:FLVPlayback = e.target.flvPlayback;

// move the caption below the video
tf.y = 210;
}
public function writeNav(){
for (var i:int = 0; i < 1; i++) {
var newCircle:videoCap.DynamicButton = new videoCap.DynamicButton();
newCircle.name = "nav" + i;
newCircle.setLabel(newCircle.name);
newCircle.setInternalVar(i);
newCircle.y = 25 * i;
newCircle.myNum = i;
newCircle.x = 120;
addChild(newCircle);
}
}
}
}


package videoCap{
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.display.MovieClip;
import flash.system.*;

public class DynamicButton extends MovieClip {
private var clicked:Boolean = false;

public function DynamicButton() {
this.buttonMode = true;
this.mouseChildren = false;
clicked = false;
this.addEventListener(MouseEvent.MOUSE_OVER, rollover);
this.addEventListener(MouseEvent.MOUSE_OUT, rollout);
this.addEventListener(MouseEvent.MOUSE_DOWN, mouseClickDown);
this.addEventListener(MouseEvent.MOUSE_UP, mouseClickUp);
this.addEventListener(MouseEvent.CLICK, mouseClick);
}

public function setLabel(thisLabel:String){
visibleLabel.text = thisLabel;
}
public function setInternalVar(thisNum:int){
myNum = thisNum;
}

public function rollover(event:MouseEvent) {
if (clicked) {
gotoAndStop("down");
} else {
gotoAndStop("over");
}

}

public function rollout(event:MouseEvent) {
gotoAndStop("normal");
}

public function mouseClickDown(event:MouseEvent) {
clicked = true;
gotoAndStop("down");
}

public function mouseClickUp(event:MouseEvent) {
clicked = false;
gotoAndStop("over");
}
public function mouseClick(event:MouseEvent) {
trace("HHHHH");
trace(myNum + " myNum");


//--------------------------//
Calling the function here.
seekToMovie();
//--------------------------//


}
}
}

lordofduct
04-07-2008, 10:07 PM
seekToMovie doesn't exist inside of the DynamicButton class... you're basically saying

this.seekToMovie();

you need to say where seekToMovie is... and it is inside of the other class. So you'll need a reference to the instance of that class, and then call it.

if it's a basic static function (non dependent of a single instance) then make it a static funciton and you can call it by a theClass.theFunction(...);

this last example is very dependent though. In a static function you can not be defining anything inside of a class that is instance dependent. i.e. a static function inside of a class that extends a MovieClip can not tell that movie clip to change its x position. the x position is instance dependent. But it can tell a reference passed through the function to change its x position. Just not its own.

TomMalufe
04-07-2008, 10:08 PM
First Class
package videoCap{
import fl.video.CaptionChangeEvent;
import fl.video.FLVPlayback;
import fl.video.FLVPlaybackCaptioning;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.system.*;

public class FLVPlaybackCaptioningExample extends MovieClip {

private var videoPath:String = "TESTVid.flv";
private var captioningPath:String = "caption.xml";

public function FLVPlaybackCaptioningExample() {
player.source = videoPath;
captioning.flvPlayback = player;
captioning.source = captioningPath;
captioning.autoLayout = false;
captioning.addEventListener(CaptionChangeEvent.CAP TION_CHANGE, onCaptionChange);
writeNav();
}

/****************************/
//I can't seem to call this function
public function seekToMovie(mySeekNum:Number):Number{
player.seekSeconds(mySeekNum);
}
/***************************/



private function onCaptionChange(e:CaptionChangeEvent):void {
var tf:* = e.target.captionTarget;
var player:FLVPlayback = e.target.flvPlayback;

// move the caption below the video
tf.y = 210;
}
public function writeNav(){
for (var i:int = 0; i < 1; i++) {
var newCircle:videoCap.DynamicButton = new videoCap.DynamicButton();
newCircle.name = "nav" + i;
newCircle.setLabel(newCircle.name);
newCircle.setInternalVar(i);
newCircle.y = 25 * i;
newCircle.myNum = i;
newCircle.x = 120;
addChild(newCircle);
}
}
}
}

Second Class
package videoCap{
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.display.MovieClip;
import flash.system.*;

public class DynamicButton extends MovieClip {
private var clicked:Boolean = false;

public function DynamicButton() {
this.buttonMode = true;
this.mouseChildren = false;
clicked = false;
this.addEventListener(MouseEvent.MOUSE_OVER, rollover);
this.addEventListener(MouseEvent.MOUSE_OUT, rollout);
this.addEventListener(MouseEvent.MOUSE_DOWN, mouseClickDown);
this.addEventListener(MouseEvent.MOUSE_UP, mouseClickUp);
this.addEventListener(MouseEvent.CLICK, mouseClick);
}

public function setLabel(thisLabel:String){
visibleLabel.text = thisLabel;
}
public function setInternalVar(thisNum:int){
myNum = thisNum;
}

public function rollover(event:MouseEvent) {
if (clicked) {
gotoAndStop("down");
} else {
gotoAndStop("over");
}

}

public function rollout(event:MouseEvent) {
gotoAndStop("normal");
}

public function mouseClickDown(event:MouseEvent) {
clicked = true;
gotoAndStop("down");
}

public function mouseClickUp(event:MouseEvent) {
clicked = false;
gotoAndStop("over");
}
public function mouseClick(event:MouseEvent) {
trace("HHHHH");
trace(myNum + " myNum");

/****************************/
//Calling the function here.
seekToMovie();
/****************************/
}
}
}

2 things that I see here.
One is that you are calling a method in a different class, so unless that method is static (which probably wouldn't be a good idea in this case) then you will need an instance to run it.
Second, doesn't it need at least on parameter? your call doesn't have any.

tsquini
04-08-2008, 08:12 PM
Thank you for your reply.

I made the function static and I was able to access the it but I could not control the FLV player. How would an Instance be structured to call this function?


/*FLVPlaybackCaptioningExample Class*/
public static function seekToMovie(mySeekNum:Number){
player.seekSeconds(mySeekNum);
}

/*DynamicButton Class*/
public function mouseClick(event:MouseEvent) {
/****************************/
FLVPlaybackCaptioningExample.seekToMovie(50);
/****************************/
}