PDA

View Full Version : checking for dynamic text and performing action



glow
October 23rd, 2008, 01:17 AM
Hi everyone I need some help with this code.

I have this button, who's text is loaded dynamically, the button text is inside an mc, I need for the dynamic text's mc to be invisible when no dynamic text is loaded and visible when text is loaded.

Currently the button on its visible state sits on frame label "on" and I've created another frame labeled "off", I just don't know how to put together the action to make the frame switch to "off" when no dynamic text is loaded to make the button invisible.

I tried doing this:


if (_root.buttons.bt1.btn1mc.text1 == "") {
_root.buttons.bt1.gotoAndStop("on");
} else {
stop();
}

but it didn't work

any help would be appreciated.

logeshps
October 23rd, 2008, 02:16 AM
this same problem i met up while doing button with dynamically loaded with php.....

i used this coding it's working....

myvars = new LoadVars();
myvars.load("login.php");
myvars.onLoad = function(s)
{
if(s)
{
here=_root.sessionname;
if(here=="")
{
log.text="LOGIN";
gotoAndStop(20);

}
else
{
log.text="LOGOUT";
gotoAndStop(20);
}
}
}.



verify this coding it may help u....

glow
October 23rd, 2008, 11:35 PM
Hi logeshps

thank you for the help. I'm pretty new to AS I'm not really sure how to apply this code to my buttons.

If you don't mind I've attached a fla, could you please see if your code works with my buttons?

glosrfc
October 24th, 2008, 07:35 AM
try this:

if (_root.buttons.bt1.btn1mc.text1 == null) {
_root.buttons.bt1.gotoAndStop("on");
} else {
stop();
}

glow
October 25th, 2008, 01:30 AM
Hi glosrfc

Thank you for trying to help out, but unfortunately that didn't work. i don't know what else to apply, I now there is a way I've seen it done, i just wish i knew how.

thanks again

glosrfc
October 25th, 2008, 02:07 PM
Ah...you need to check the .text property:
if (_root.buttons.bt1.btn1mc.text1.text == "" || _root.buttons.bt1.btn1mc.text1.text == null)

Incidently, you can also use the ._visible property on your button instead of creating an empty frame:
_root.buttons.bt1._visible = "false";
} else {
_root.buttons.bt1._visible = "true";
}

glow
October 25th, 2008, 10:26 PM
glosrfc your golden man. :)

That worked out great, thanks a million. thanks for the help.

:party:

glow
October 25th, 2008, 11:57 PM
glosrfc can I trouble you with another question regarding the The "if" statement? I have this dynamic mini slide show that loads 8 external images. I need for some type of check system that checks whether an image is loaded or not so if the image is loaded it goes to that images containers frame and plays it if image is not loaded than it goes and plays from frame 1. I have the image mc containers set at every 50 frames. thanks again.

glosrfc
October 26th, 2008, 10:43 AM
Take a look at the MovieClipLoader class to load your images...this has built-in event handlers to monitor things like loading progress, successful loading, loading errors, etc. There's also no need to have separate mc containers on different frames. Just have a single container into which you load the appropriate image when required. Look at some of the threads elsewhere in this forum; questions about the MovieClipLoader class are asked on a daily basis.

glow
October 26th, 2008, 12:12 PM
glosrfc

Im using this code for the image loading:


MovieClip.prototype.fadeIn = function() {
this.onEnterFrame = function() {
if (this._alpha<100) {
this._alpha += 10;
} else {
delete this.onEnterFrame;
}
};
};
bar._visible = false;
border._visible = false;
var empty = this.createEmptyMovieClip("container", "100");
empty._x = 0 - 150;
empty._y = 0 - 100;
my_mc = new MovieClipLoader();
preload = new Object();
my_mc.addListener(preload);
preload.onLoadStart = function(targetMC) {
trace("started loading "+targetMC);
container._alpha = 0;
bar._visible = true;
border._visible = true;
pText._visible = true;
};
preload.onLoadProgress = function(targetMC, lBytes, tBytes) {
bar._width = (lBytes/tBytes)*100;
pText.text = "% "+Math.round((lBytes/tBytes)*100);
};
preload.onLoadComplete = function(targetMC) {
container.fadeIn();
border._visible = false;
bar._visible = false;
dText._visible = false;
trace(targetMC+" finished");
};

///resizing code

my_mc.onLoadInit = function (targetMC)


{
myTrace ("Movie clip:" + targetMC + " is now initialized");


targetMC._width = 498;
targetMC._height = 498;
}

//default image
my_mc.loadClip(_root.contenturl1 + "/" + _root.userid + "/img1intro.jpg", "container");



I'm kinda stuck now I'm afraid that my AS abilities are kind of limited still.
The containers are on different frames to provide the amount of time for wish each image stays loaded than it moves on to the next image container frame.

Just like you did for me for the checking of the "text property" it would be great if I could do something similar with the image container, something like:


stop();
if (_root.banner.imagecontainer2 == null) {
_root.banner.gotoAndPlay("Frame1");
} else {
play();
}

that was just something that I tried and didn't work, i was just wondering what would be the right code to execute something like that?

thanks glosrfc

glosrfc
October 26th, 2008, 01:30 PM
The point I was making is that you don't have to use any conditional statements to check if an image has been loaded...the MovieClipLoader class handles all of that for you. That's why there's an onLoadProgress, onLoadComplete, and onLoadInit in that portion of code. These handlers are triggered when: the loading has started, the loading is complete, and when the loaded clip is initialised. This code also creates a container for the clip on the existing frame and loads the content into it, as well as resizing it, once it's loaded and initialised. I don't understand why you need to create different container clips on different frames.

glow
October 26th, 2008, 03:01 PM
glosrfc thank you for taking the time to talk tome about this.

I'm sure there are more sophisticated ways to implement this with the MovieClipLoader class but like I was saying before, My AS knowledge is very limited so conditionals are the easiest implementations that i could sort of relate with and follow, so if conditionals could also be used in this case I would very much like to know how to apply it because believe me when I tell you that unless you told me exactly how to do it with the MovieClipLoader class I wouldn't have the slightest idea on how to go about doing it that way.

thanks glosrfc