PDA

View Full Version : Lights On/Off


BenAllen
01-28-2003, 09:59 AM
I have 5 lights that are activated by five buttons. When the lights are activated they fade up, and fade out when they are deactivated.

My problem is I can't get my head around developing a script that checks to see which lights are on and if they are on, to fade them out.

Obviously only one light can be on at any one time. But i keep having numerous lights fading up and out and I'm tearing my hair out.

Thanks in advance for any help.

linckx
01-28-2003, 10:14 AM
Hi Ben, welcome to as.org

try with a variable?

light1="on";
light2="off";

etc... ?

robin

BenAllen
01-28-2003, 10:32 AM
Hi Robin,

Thanks for the kind welcome.

If I'm not doing Hillman Curtis out of a job soon from this site, i'll eat my mouse mat.

My lights are movie clips that have tweening in them. One that fades up and one that fades out.

I managed to get light 1 to light up and then when I clicked on light 2 it lit up as light 1 faded out.

My problem occurred when I try to light up light 3. I have all sorts of lights on the go.

What am I doing wrong?

linckx
01-28-2003, 10:39 AM
as long as there are only five or six lights you might just do something like

on release(){

_root.myInstanceName1.gotoAndPlay("fade_in");
_root.myInstanceName2.gotoAndPlay("fade_out");
_root.myInstanceName3.gotoAndPlay("fade_out");
_root.myInstanceName4.gotoAndPlay("fade_out");
_root.myInstanceName5.gotoAndPlay("fade_out");


}




robin

BenAllen
01-28-2003, 12:44 PM
Thats good,

But when I run that script it fades in the first light and fades out all the other lights, even though they are not even on.

I need something that checks whether or not a light is on, if it is fade out, if it isn't do nothing. I understand the logic but don't know how to put it in a script.

linckx
01-28-2003, 12:47 PM
that's what I meant with assigning the variable (in my first post)
probably wasn't clear enough...

You should give a variable with the actions like
light1="on";

and when you click another light

light3="on";

and then on your button put an if function to check which variable is active, and change that one...

If you've got some time I'll try to make you a sample file

:)robin

BenAllen
01-28-2003, 12:54 PM
Yeah,

I've got the time.

Cheers

Your help is much appreciated.

dr.swank
01-28-2003, 01:26 PM
hey there! welcome from me as well :)

ok, to your problem. it sounds like you need to work with toogle variables and conditionals.

if your light_mc's go from off on frame1 to on on frame 20 and then back to off on frame 40, then put a stop() on those frames and a gotoAndStop(1) on frame 40. Now you can controll what the lights do.

after that you need to add a toogle. For the sake of this case I will not get into complex toggling, that being said put the following on frame 1 of your lights:

I attached a file that should help out. Take a look and get back to us if you have any problems.

cheers, dr.s

linckx
01-28-2003, 01:29 PM
well: the doctor said it best, I was only halfway the little file, but with this you've allready got one, so I'll leave you in the doctor's capable hands :)

friendly greetings

robin

BenAllen
01-28-2003, 01:41 PM
Thanks for the help,

I'll let you know how I get on with that later.

However, I have a new problem, and I know its dead simple, but I just can't seem to understand it.

I have a main timeline.

I want to load an mc into frame 2. This mc is about 200 frames long, when it is finished I want to load a new mc into frame 3 and so on.

Basically its for an advert/commercial cycle that i need to put on a web site.

Initially i have tried to point the user back to the main timeline, by adding a frame label to frame 3 of the main timeline. However in frame 200 of the mc I can't seem to ber able to point to the frame label.

I know its really stupid, and I'm sorry for taking up anyones time, but I believe I need to get the basics straight in my head, and then I can develop quicker.

Again

Thanks for your help.

BenAllen
01-28-2003, 01:59 PM
Thanks for the script it works great, however....

when i click over the buttons too quickly the lights stay on, is this just a bug in flash is there a way to clean this up.

BenAllen
01-28-2003, 01:59 PM
Here is my script that I adapted from your script.

binkyboo
01-28-2003, 02:33 PM
I took a slightly different approach and utilized Jesse's reverse movieclip prototype. The code is ugly and can certainly be cleaned up but it's a different approach. I was working on it when I noticed Dr. Swank had posted an example but I thought I'd continue and post it anyways.

dr.swank
01-28-2003, 02:34 PM
so I'll leave you in the doctor's capable hands



dr.s blushes and says:" aww schucks, hehe"

any ways, to the aliment at hand. There are many ways to make the light not stay on. I think it would be easiest to make the light_mc contain 2 mc's: 1 to glow up and 1 to glow down. At the end of each of these "nested" mc's you put a _parent.gotoAndStop() to the frame where it should be. I could do it for you, but I think that you shoukld try it yourself first. That the best way to learn it.

As for the issue of the 200 framer, tell me how you are loading it and I will give you a hand.

cheers, dr.s

BenAllen
01-28-2003, 02:52 PM
Well i want to load it as an mc into the main timeline.

Tell me am I doing this wrong, is it possible to have endless external swf files or can it all be embedded in the main movie.

I also didn't want to have numerous scenes either.

basically...

I need to have around 5 advert/commercial movies that follow on from each other. But i want to keep them seperate from eachother so I can edit them when we need to update the adverts.

Thanks

PS.

Thanks for the last bit of help, it turns out that it only happens when you really quickly press the buttons.

So i'm going to risk that.

dr.swank
01-28-2003, 03:19 PM
thats not a problem at all. I would suggest loading them into a "container"

if you put an empty mc (create a new symbol instance with nothing in it called container) and place it on stage. make sure that it posission is the same as where your film to load will be. Then name it container1. now you can load your swf "into" that container.


loadMovie("myAd.swf","container1")
// or
container1.loadMovie("myAd.swf")


you can also set the visibility by adding

container1._visible=0


now if you load all of your files this way and then make either a timed loop or you put the visible=1 code at the end of each film you will have all of your data loaded and then they will play.


//on the last frame of film 1
_root.container2._visible=1
this._visible=0


the advantage of the container is that you can tell it where to go, ie you have access to its _x and _y props.

does this help??

BenAllen
01-28-2003, 03:24 PM
Thanks very much

You've been a great help today, maybe tomorrow I'll be able to climb bigger mountains.

dr.swank
01-28-2003, 03:27 PM
my pleasure.:)

BenAllen
01-29-2003, 08:58 AM
Good morning, last night I studied your script and this morning I tried to enact it.

Unfortunately when I load "advert1.swf" into container1, and then try and set the visibility of container1 to 0 it doesn't work, it just shows the advert1.

I will get this right eventually.

dr.swank
01-29-2003, 09:27 AM
hmmm.. it might be the path I told you to use...

try setting the _visible from the root level:


_root.container1._visible=0


I just threw the "this" in there without much thought.

:)

BenAllen
01-29-2003, 09:45 AM
Oh this is really getting to me.

When I load the movie into container1, it doesn't appear in the centre of the movie clip. It appears to the right and below.

I've attached a zip of my fla's,

I have an advert_main
and advert1.

What am I doing wrong?

dr.swank
01-29-2003, 10:18 AM
thats easy enough, use the align tool to align the container1 to the top left corner of the stage. I just did it and it works. As a note a loaded mc into a container always aligns with to the top left corner also known as _x=0 _y=0. No big deal.

;) dr.s

BenAllen
01-29-2003, 11:55 AM
So is the code correct?

loadmovie("advert1.swf","container1")
_root.container1._visible=0

I want to load the clips into the containers at the start, and then I can change the visibility to 1 whenever I need them.

linckx
01-29-2003, 12:00 PM
you might wanna put semicolons ( ; ) --> don't know if I'm using the right word...


behind both lines...

for the other parts I don't see any mistakes... but I've never used _visible on targets...

robin

BenAllen
01-29-2003, 12:10 PM
Cheers,

I actually used _alpha instead and it seem to work, are the semicolons necessary? Its just that I have got it to work fine without them. Is it just good for neat code, I dont want to be messy.

linckx
01-29-2003, 12:13 PM
to be honest I don't actually know if they're always necessary, but they (if they don't do anything) won't do you harm...

In some cases it's necessary to use them, so it's easier to make it a good habbit now, than having to adjust many things later :)

robin

did your project turn out to be fine now?

BenAllen
01-29-2003, 12:16 PM
It seems to be, no doubt i'll be back on for more help, but I suppose its all part of the learning process, i'm starting to understand the logic more now.

Thanks

BenAllen
01-29-2003, 02:30 PM
Well I was doing so well, and now i've hit a snag.

My advert 3 seems to appear during advert 1.

I have set the script to load all 3 adverts into containers 1,2 and 3 on the first frame of the main movie.

At the end of each advert I change the alpha setting to 100 for the new advert and 0 for the one just played.

I've attached the files to look at it.

What am I doing wrong?

dr.swank
01-29-2003, 04:18 PM
well, sorry for being absent, I am on a job at the moment and can't always check my mail. Any how,.. the semicolons are good for, if you use the auto format button at the top beside the code check it will format you code and put semicolons behind every line as necessary.

Using alpha has advantages AND disadvantages. The main one being that an alpha=0 button still functions whereas a _visible=0 button does not. Its not key for what you are doing but it might be later.

I will look through your code later tonight when I get a chance.

happy coding, dr.s

BenAllen
01-30-2003, 07:52 AM
Thanks,

I look forward to hearing from you

dr.swank
01-30-2003, 02:11 PM
just checking in to let you know that I am enroute to my office again, through the snow.... this could take a while. I'll be back online tomorrow morning.

cheers, dr.s

dr.swank
02-02-2003, 05:04 PM
HI BenAllen,

I have bin fidgeting around with your file and have come up with something pretty cool. It's not done but take a look at you output window when testing the main.fla. I will keep cracking at it and get back to you later.

cheereo, dr.s

dr.swank
02-02-2003, 05:16 PM
wow, that was fun fun fun...

here you go, 1 ready to use advert switcher auto loader thingie.

enjoy! dr.s

http://www.juliansanderobjekte.com/asorg/Adverts10.2.zip

ps. i put a link to the file because it was too big and I was not in the mood to shrink it down.;)

dr.swank
02-02-2003, 06:55 PM
HI BenAllen,

I have bin fidgeting around with your file and have come up with something pretty cool. It's not done but take a look at you output window when testing the main.fla. I will keep cracking at it and get back to you later.

cheereo, dr.s

BenAllen
02-03-2003, 08:53 AM
Cool,

I'll look forward to seeing it, oh and thanks for the other Flash file, I'll study it and maybe I will be able to do it myself.

Cheers

dr.swank
02-03-2003, 09:01 AM
BenAllen,

the main trick I used was the Ben.counter as a global variable. It counts for you, and resets itself after it reaches a number you specify. as for the alighnment issue, I aligned your container to the top left of the main mc thus making the adverts load in the right place.

let me know how you do with it.

cheers, dr.s

BenAllen
02-03-2003, 09:14 AM
So basically, the variable bencounter, adds 1 to itself and automatically loads the next advert as a result.

Fairly simple enough, is there anything you don't know?

dr.swank
02-03-2003, 09:22 AM
oh yes, much to learn, but learning is a collective thing. you help someone and you get helped. no bitterness no envy, just help. my small bit to make the world a better place. :)

make sure that you think about the theory of what I showed you. code is dumb and needs to be told every thing, but it really only understands very little. its like lego, it you know what blocks you have, and understand how they work, then you can build big things. Also, check the adverts, and not that on the last keyframe is the function call that adds to Ben.count and loads the next Advert...

If you need any more explinations just post here or a new thread and I will try and help.

cheers, dr.s :D

BenAllen
02-03-2003, 01:19 PM
So I have been looking at the script to try to decipher it, and make myself understand it more easily.

On the advert movies, you have this script at the end of the movie:

//stop()
//_parent.filmCount++
Ben.counter()

So the info following the // is a comment and is not part of the script. Just need to clarify.

linckx
02-03-2003, 01:23 PM
indeed

and when you want to out-comment larger parts you can use


/* to start
blabla
blabla
blabla
blabla
blabla
*/

to stop



robin :)

dr.swank
02-03-2003, 01:30 PM
rightOO,

I left those commented code lines in there because it was an earlier attempt to do the same thing before I decided to use a global function. :) you can erase them if you want.

dr.s

BenAllen
02-03-2003, 01:40 PM
okay,

you sound really proud of this movie. Its definitlely going in my help book.

just one question, on the first actionscript on the first frame of the first movie (phew!), you have added the loadMovie twice, is that accidental or is there a reason behind it?

dr.swank
02-03-2003, 01:52 PM
that is on purpose. The function doesn't get called until the end of advert1, so I force the first film , advert1, to load to get the whole thing going. It's an init if you want.

cheers, dr.s

BenAllen
02-03-2003, 01:58 PM
Ok, I think I understand.

The first one is to initialize the movie and the second one actions it, or have I got that wrong.

dr.swank
02-03-2003, 01:59 PM
nail on the head! don't forget to show how the whole thing turns out. I am very curious.

dr.s

BenAllen
02-03-2003, 02:05 PM
No problem, were having a bit of trouble with our servers at the moment, so when its up i'll send you the link, or I may even use it on my site, but I will put a comment in the source file that it was done with a lot of help from yourself.

The idea of it was that we are going to sell ad space on a governmental assessment web site. So I wanted something that I could update and add to. So I think I have it now.

Cheers

and to Rob too

dr.swank
02-03-2003, 02:10 PM
very hip, you may want to check into the XML object at a later time to aid in making things dynamically updateable. It's a bit wierd at first, but once you get it, it is very usefull.

good luck, and thanx for the honorable mention.

cheers, dr.s

BenAllen
02-06-2003, 09:09 AM
XML?

Where can I get a good tutorial on XML, thats clear. You know like XML for Dummies. I think as I want to be a good flash designer, i'm learning all the time, but I need to know XML as well.

Oh by the way i've started a new thread for dynamic text, see if I can get it as long as this one.

Many Thanks

dr.swank
02-06-2003, 09:24 AM
here is jesse's tut. it's a good place to start

http://www.actionscript.org/tutorials/intermediate/XML/index.shtml

cheers, dr.s