View Full Version : Accessing a variable in frame 5 from an actionscript as file loaded in frame1
Raneru
03-17-2005, 12:50 PM
In frame 1 I create a movieclip. This movieclip is exported to an .as file.
This movieclip has 2 frames. On frame 1 there is a button and on frame 5 a textinput object. I put an empty keyframe on frame 4 so that frame 5 only contains the textinput and not the button.
my code looks like this:
import mx.controls.Button;
import mx.controls.TextInput;
Class Test{
var ti:TextInput;
var bt:Button;
function onLoad(){
bt.onRelease = dosomething;
ti.text = "test"; //this does NOT work.
}
function dosomething(){
this.gotoAndStop(5); //this works
}
}
So my question is this:
How do i access the object that is located in frame 5? I want to access it from my .as file that is loaded in frame 1.
I hope you understand my question.. People seldom do.....because I stink at explaining stuff..
Ricod
03-22-2005, 12:09 PM
It's been a while, so I'm a bit rusty. But, shouldn't your textfiled be a dynamic textfield in order to change it's content ? An input field is for user input. But maybe you can change text in input fields, I don't know for certain, since I've never tried it. Also, the variable for the textfield should match your addressed variable (ti.text).
Raneru
03-22-2005, 12:24 PM
I guess you are right, but my problem is really just this:
How do I access something in frame 5 from frame 1?
When is frame 5 instanced?
If I in frame 5 make a Button-object
how do I in frame 1 access this button object?
I've tried using the same dot-notation that I use when accessing objects in frame 1.
I would want to type somthing like this:
_root.main_mc.button1:5
where 5 denotes that this button exists in frame 5 and not before.
But I don't even understand my own question here. If I could explain my question then I guess the answer would be very simple. This is child stuff really..
Another thing... Does it exist some kind of Actionscript user guide for those who knows how to program Java or C++ or any other "REAL" programming language?
Roar
senocular
03-22-2005, 12:29 PM
You cannot access objects that do not yet exist, i.e. in other frames if they are not present in the current.
Alternative:
define your text value in a variable in the timeline and in the frame where your textfield exists, add actionScript that assigns the value of that variable to your textfield text.
Raneru
03-22-2005, 12:42 PM
That was what I wanted to know. I'll try to follow your alternative method, senocular.
And again..thanks for the anwer.
senocular
03-22-2005, 02:06 PM
welcome. I hope it works for you.
Ok, I have kind of the same problem but a just a little bit different. I have a game where I have a frame for the multiplayer and a frame for sigle player. I have declared some functions on the main timeline to the multiplayer frame (which comes first) and I inserted a regular frame on the same layer where the functions are so that it would be the same for the single player. When I try to access the funtion from the multiplayer (first one) it works fine but the functions don't seem to follow through to the single player frame (the next one). If I change the frame on the single player to a keyframe and copy and paste the code it works fine but I would like to be able to just edit the functions once and not have to copy and paste every time I make a change.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.