View Full Version : Dynamic text problems
coskier
02-09-2006, 06:20 PM
I am quite new to Flash, but picked up a copy of Flash Pro 8 Unleashed. I am trying to create a movie with a dynamic text component, where the text is coming in froma php page (and thus, coming from a database).
Here's the problem:
I have a dynamic text field with an instance name of textField_txt. When I use the following code, the text does *NOT* appear in the field.
var myString_str:String = "test 2"
textField_txt.text = myString_str;
However, if I add a Var name to the field and use:
var myText = "testing";
it works fine.
Any ideas here? I am not sure if fixing this will fix the more complex problem of reading in the data from the php file and displaying that (which it is not doing either).
Thank you.
Chester
mcmcom
02-09-2006, 06:38 PM
Are you publishing using Actionscript 1.0 or 2.0?
i think (but am not sure) that the format
var myStr:String = new String();
myStr = "Test";
is Actionscript 2.0 and:
var myVar = "mystring";
is Actionscript 1.0.
Check your publishing settings and try each one out.
HTH,
MCM
coskier
02-09-2006, 06:44 PM
Publish settings are to use ActionScript 2. I take it the syntax is correct?
mcmcom
02-09-2006, 06:49 PM
hmm... well i noticed a semicolon is missing on your first post, but that shouldn't matter (fix it though if its missing in your code).
maybe try
var myString:String = new String();
myString = "test";
_root.myTextfield.text = myString;
PS Also make sure you reference your text field proiperly, try to use _root.myTextField.text = "whatever"; or this._parent.myTextField.text = whatever. Just to make sure it's specific.
let me know
mcm
coskier
02-09-2006, 06:52 PM
That seems to have resolved that piece (thanks a million!). Now I will need to test if it is reading the php file to get the variable part...
mcmcom
02-09-2006, 06:53 PM
your best bet is to leave it the way it was, and set up a proper testing environment. Send and Load Vars is there to ensure that what your sending gets Sent, thats WHY it checks it.
regards,
mcm
coskier
02-09-2006, 06:57 PM
your best bet is to leave it the way it was, and set up a proper testing environment. Send and Load Vars is there to ensure that what your sending gets Sent, thats WHY it checks it.
regards,
mcm
Not sure what you mean. But I had planned on using a LoadVars statement to get the text (that is supposed to be dynamic) from the php file.
Well, after this boring conference call that is.
mcmcom
02-09-2006, 07:00 PM
i just mean that using SendAndLoad in the same function call will reduce the amount of data having to pass back and forth between PHP, flash, and will let you know right away if the send was successfull. SendAndLoad is designed to provide a kinda "Ya" or "No" answer to what you just did, and you can return just a bit to determine if it was a success or not.
MCM
coskier
02-09-2006, 07:18 PM
Ah, OK. Still learning all the functions.
This is what I was going to try and work from:
function getSong() {
var getAll_lv:LoadVars = new LoadVars();
getAll_lv.onload = function (success) {
if(success){
//get the data being returned
var title = this.title;
var artist = this.artist;
var myText = title + " by " + artist;
} else {
trace(this.error);
}
}
getAll_lv.load("http://www.willie925.com/now_playing.php");
}
getSong();
coskier
02-09-2006, 07:45 PM
Well, I tried this:
function getSong() {
var myString:String = new String();
var myLoader_lv:LoadVars = new LoadVars();
myLoader_lv.load("http://www.willie925.com/now_playing.php");
myLoader_lv.onLoad = function(success:Boolean) {
if(success){
return "Now Playing: "+ this.title;
} else {
return "an error has occurred";
}
}
}
var myString = getSong();
_root.myTextfield.text = myString;
But when I run the movie, I get "undefined" in the text field. Ideas?
coskier
02-10-2006, 02:20 PM
Wow - this forum gets a lot of traffic. Anyone have additional thoughts on this problem? I just get "undefined" now.
mcmcom
02-10-2006, 04:06 PM
your problem is the "This" keyword.
this.title is nothing if you want the title for the movie you have to rename this to myLoader.title. But if title is not in the LoadVars you cant get it. i dont think flash is smart enough to look in video files and get names.
coskier
02-10-2006, 09:43 PM
Based on the example I saw, "this" is used in reference to the variables that are coming to the LoadVars function via the php page. Is that not the case?
(The code, so people don't have to flip back and forth)
function getSong() {
var myString:String = new String();
var myLoader_lv:LoadVars = new LoadVars();
myLoader_lv.load("http://www.willie925.com/now_playing.php");
myLoader_lv.onLoad = function(success:Boolean) {
if(success){
return "Now Playing: "+ this.title;
} else {
return "an error has occurred";
}
}
}
var myString = getSong();
_root.myTextfield.text = myString;
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.