PDA

View Full Version : is it possible to access class variables from timeline?



numediaweb
November 24th, 2008, 09:51 AM
Hello there
I have a document class myClass, where i set a variable:


var playhead:String = new String("");
index_menu_bar.menu_bar.btn_menu.addEventListener( MouseEvent.MOUSE_OVER, MouseOverBar);
function MouseOverBar(e:MouseEvent):void{
index_menu_bar.playhead = "hs";
index_menu_bar.play();
}

and in the timeline I have a movie clip index_menu_bar inside it, say in frame 25 I have this script hat tries to get the variable from the class


stop();
gotoAndPlay(playhead);

but i got error:

1120 : access to undifined property playhead
as you can see i already defined this property on my class!!
any clews?
thanx

GrndMasterFlash
November 24th, 2008, 10:29 AM
cast it as public!

public var playhead:String

**edit**

also make sure it's not declared inside of a function

watcher
November 24th, 2008, 10:31 AM
hi there.

Maybe just make the playhead variable public. But im not sure, i would have to get my hands on your FLA and stuff. Here is a working example however:

Document class called MyClass, with content:


package {
import flash.display.MovieClip;

public class MyClass extends MovieClip {
public var myVar:String = "test";

public function MyClass(){}
}
}



on stage there is movieclip, name not important, inside on N-th frame is this code:


stop( );
trace( MyClass(parent).myVar ); // traces: test


Hope it helps! :)

numediaweb
November 26th, 2008, 05:33 AM
thank you guys for the help.
I managed it using only class code (cause puting code on both class and timeline is not advised!)
her's the code on the class


var playhead:String = new String("start");
index_menu_bar.menu_bar.btn_menu.addEventListener( MouseEvent.ROLL_OVER, RolOverBar);
index_menu_bar.menu_bar.btn_menu.addEventListener( MouseEvent.ROLL_OUT, RolOutBar);
function RolOverBar(e:MouseEvent):void{
if(index_menu_bar.currentLabel == "f_s"){
playheadsetter("f_s_2");
}else if(index_menu_bar.currentLabel == "f_h"){
playheadsetter("f_s_2");
}
}
function RolOutBar(e:MouseEvent):void{
if(index_menu_bar.currentLabel == "h_h"){
playheadsetter("h_h_2");
}
}
function playheadsetter(playhead){
if(index_menu_bar.currentLabel != playhead){
index_menu_bar.gotoAndPlay(playhead);
}
}