Copy link to clipboard
Copied
In my project I have 24 different frames with different visual content. On frame one I have a dynamic text box that is supposed to display a currently selected list item. On frame 24 is the selection list with 4 options to choose. I am wanting the content of a different box to be assigned back to frame 1 when pressed on frame 24. My code for both frames is below. Any suggestions are appreciated.
Frame 1
var stateLast: int = 1;
var SChem: String = 'Chem1';
var c1: String = 'Chem1';
var c2: String = 'Chem2';
var c3: String = 'Chem3';
var c4: String = 'Chem4';
var modeLast: int = 1;
SelectedChem.text = SChem;
function SelectC1(event:MouseEvent): void {
SChem = c1;
SelectedChem.text = SChem;
trace(SelectedChem);
}
function SelectC2(event:MouseEvent): void {
SChem = c2;
SelectedChem.text = SChem;
trace(SelectedChem);
}
function SelectC3(event:MouseEvent): void {
SChem = c3;
SelectedChem.text = SChem;
trace(SelectedChem);
}
function SelectC4(event:MouseEvent): void {
SChem = c4;
SelectedChem.text = SChem;
trace(SelectedChem);
}
Frame 24
Chem1.text = c1;
Chem2.text = c2;
Chem3.text = c3;
Chem4.text = c4;
HomeBtn.addEventListener(MouseEvent.CLICK, GoHome);
sc1.addEventListener(MouseEvent.CLICK, SelectC1);
sc2.addEventListener(MouseEvent.CLICK, SelectC2);
sc3.addEventListener(MouseEvent.CLICK, SelectC3);
sc4.addEventListener(MouseEvent.CLICK, SelectC4);
Copy link to clipboard
Copied
if you want to use SelectedChem.text in a frame where SelectedChem doesn't exist, assign SelectedChem.text to a variable and use that variable similar to what you're already doing with c1 etc.
Copy link to clipboard
Copied
SelectedChem is the dynamic text box on frame 1 only. Chem1-4 are visual labels with buttons sc1-4 ontop. Later I plan to make them editable on a different screen and need them to be able to change when the user edits that field but for now I am still trying to learn to manipulate text with AS3 in Flash.
Copy link to clipboard
Copied
this is the error that pops up when I go to push the button in frame 24 in test mode.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at us1pc6915_fla::MainTimeline/SelectC2()[us1pc6915_fla.MainTimeline::frame1:195]
Copy link to clipboard
Copied
you're trying to reference a non-existant object on line 195 of frame 1.
if you don't see how to fix that, what is line 195 of frame 1?
Copy link to clipboard
Copied
Line 195 is
SelectedChem.text = SChem;
this is where I am calling it to reassign with the changed SChem value inside the function.
Copy link to clipboard
Copied
i assume you change the value of SChem and you want SelectedChem to display that new value. if not, you better explain that.
but why are you trying to change the text property of SelectedChem when it doesn't exist?
if and when you return to frame 1, you might want to change it but it makes no sense to change it when it doesn't exist and therefore isn't being displayed.
Copy link to clipboard
Copied
but SelectedChem does exist in frame 1 as a dynamic text object. when i start the text it shows in the scene as Chem1 like I call it to in the beginning of my code in frame 1 with var SChem. and I am trying to change it by changing the SChem var SelectedChem is looking at.
Copy link to clipboard
Copied
does it exist when you see that error message?
answer: no.
and that's the problem.
Copy link to clipboard
Copied
Ok. I realize now that I was staying on the frame that didnt have that text object. I changed my function to move me back to the frame that had that text object before changing the variable. I first tried to extend the object I was trying to change through all of my frames outside of the visible scene but that didn't work. Is that not an option for handling this type of situation if I didnt want it to change back to the other frame?
Copy link to clipboard
Copied
if you don't move to a frame where SelectedChem exists, why would you want to change its text property? there's never a reason to do that.
you can change the value it will be assigned anytime you want and that's what you do when you change the value of SChem. then that value is waiting to be used whenever SelectedChem is next displayed.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now