Click to See Complete Forum and Search --> : Simple Actionscript help?
gobosox
08-14-2007, 02:44 PM
Im trying to write a function for navigation. In theory it seems simple, but its frustrating me nwo, any help would be great.
There are 5 buttons and a projector screen. In the intro the projector screen comes down and goes up (all used with frame animation). No i need a script that will recognize that the screen is either up or down, so what ever button is clicked it wont put the screen down again, and again..and if its the first button clicked after the intro it knows its up. I would like it to move fluidly like a remote controlled screen. Well im knew to actuall actionscripting and this is the garbage i came up with. Any help would be greatly appreciated
stop();
var nScreenUp:Number = -252.8;
var nScreenDown:Number = -41;
var projScreen:MovieClip;
function toggleScreen(): {
if (projScreen._y = nScreenUp) {
projScreen._y = nScreenDown
}
else {
projScreen._y = nScreenDown
}
}
this.one_mc.onRelease = toggleScreen;
this.two_mc.onRelease = toggleScreen;
this.three_mc.onRelease = toggleScreen;
this.four_mc.onRelease = toggleScreen;
this.five_mc.onRelease = toggleScreen;
Webjedikungfu
08-15-2007, 05:01 AM
Howdy,
First go into your projScreen movieclip and create two "videoState" vars on an actions layer. One false and one true, like so:
Anywhere inside that clip where the projScreen is expanded out, or is in the process of expanding out should have this var:
var videoState = false;
Anywhere inside that clip where the projScreen is retracted in, or is in the process of retracting in should have this var:
var videoState = true;
This image shows how the timeline inside of projScreen should look for this example, the vars above are in the actions layer assigning the "videoState". Labels layer shows the span of each state and assigns it a name for that state.(retractin or expandout)
http://www.flashbuilding.com/images/WebDev/axpic.jpg
Then back outside of your "projScreen" movieclip, place this code for your buttons:
this.one_mc.onRelease = function(){
if (projScreen.videoState == false) {
this.projScreen.gotoAndPlay("expandout");
} else if (projScreen.videoState == true) {
this.projScreen.gotoAndPlay("retractin");
}
}
Hope that helps, may be too complicated for your needs but it works solid in my Apps. Or you might be able to pull some shred of reference from it.
gobosox
08-15-2007, 08:33 AM
thanks, that seems to make sense, is this actionscript 2 or 3? It doesnt seem to be working. I placed the vars in the proScreen movie clip to define the states. Also curious why you didnt have :Boolean on the vars? Now what if i wanted this to be a stand alone function so i didnt have to have this script for every button?
sorry if this is a pain..may be easy and im just not getting it.
Webjedikungfu
08-15-2007, 09:25 AM
It's ActionScript 2.
Function for buttons below:
Are you adding individual assignments for buttons as well.
Like gotoAndPlay("page2"); or something?
one_mc.onRelease = toggleScreen;
two_mc.onRelease = toggleScreen;
three_mc.onRelease = toggleScreen;
four_mc.onRelease = toggleScreen;
five_mc.onRelease = toggleScreen;
function toggleScreen():Void {
if (projScreen.videoState == false) {
this.projScreen.gotoAndPlay("expandout");
} else if (projScreen.videoState == true) {
this.projScreen.gotoAndPlay("retractin");
}
}
Now just make sure your vars are in the correct place inside the "projScreen" movieclip.(true and false)
var videoState = false;
With ActionScript 2 this should work hopefully.
gobosox
08-15-2007, 10:43 AM
on the timeline that you showed before, you had the buttons and the screen animation on the same timeline. within the projScreen instance, i have the animation going, so the frame with the expand title will carry the "true" var, correct? And the retract keyrame will have the "false" var? Also i will be adding other functionality to the buttons, such as gotoAndPlays....
thanks!
gobosox
08-15-2007, 11:00 AM
also getting this, not sure why
Scene=Scene 1, Layer=actions, Frame=1: Line 9: '{' expected
function toggleScreen():void{
Scene=Scene 1, Layer=actions, Frame=1: Line 20: Unexpected '}' encountered
}
Webjedikungfu
08-15-2007, 12:05 PM
Hiya,
expandout = false, inside of projScreen
retractin = true, inside of projScreen
My layer you see named buttons displays a larger menu inside of projScreen when the screen fully expands, there are like 30 buttons I have appear when my screen fully expands. Get my buttons layer out of the pic, out of your mind, it does'nt apply. It's just some content that shows up in the fully expanded frame in my paticular movie. Your "one_mc" lives outside of projScreen I presume?
So just maybe focus on getting one button to control the screen right at first, then create the function to rule all buttons when you see it working.
this.one_mc.onRelease = function(){
if (projScreen.videoState == false) {
this.projScreen.gotoAndPlay("expandout");
} else if (projScreen.videoState == true) {
this.projScreen.gotoAndPlay("retractin");
}
}
Once you get one working the rest will be a snap.
Webjedikungfu
08-15-2007, 12:11 PM
I know it sounds crazy but it works, I'll make a small .fla so everyone can see it working. And can download it. Once you open it you'll see what's happening.
Sit tight.
Webjedikungfu
08-15-2007, 12:42 PM
OK, problem solved. My code was slightly off.
Click here to see it working :http://www.flashbuilding.com/zip_dir/projScreen.swf
Click here to obtain source .fla :http://www.flashbuilding.com/zip_dir/projScreen.zip
Working example:
http://www.flashbuilding.com/zip_dir/timeline.gif
this.one_mc.onRelease = function () {
if (projScreen.videoState == false) {
projScreen.gotoAndPlay("expandout");
} else if (projScreen.videoState == true) {
projScreen.gotoAndPlay("retractin");
}
}
// this code does not go in that timeline pictured,
// it goes one level up, above it. For buttons outside of it.
Function for multiple button Screen control:
one_mc.onRelease = toggleScreen;
two_mc.onRelease = toggleScreen;
three_mc.onRelease = toggleScreen;
function toggleScreen():Void {
if (projScreen.videoState == false) {
projScreen.gotoAndPlay("expandout");
} else if (projScreen.videoState == true) {
projScreen.gotoAndPlay("retractin");
}
}
gobosox
08-15-2007, 01:02 PM
thanks, i will have to take a look when i get home, thank you for all your help. Just out of curiousity, was it possible to do them with the movie clip properties _x & _y? like i was doing before or was that not a good idea? Like i said, im new to AS and am finder there are 50 ways to do something and like 2 are right.
now if i want to and more functionality to the buttons all (loading a page on top of the screen after its open) i probably have to write another function or add to this one right, so it throws a delay if the screen has to come down correct? and if its down the page on top just comes up....that correct...? By the way i really appreciate all of your help its tough to get a grasp on the concepts initially!
gobosox
08-15-2007, 01:11 PM
one last question, did you do this in flash 8 or cs3? at the computer im on now only have mx....keeps crashing it, why im assuming your on a later version? Have cs3 on my other computer..
Webjedikungfu
08-15-2007, 01:39 PM
No sweat buddy,
Yeah, I have CS3, but saved as a flash 8 version.
I don't see why you would'nt be able to use your math in it. Should work.
Are you creating a page system for a website? To where when the user presses these buttons new pages are brought forth inside the projScreen?
Cuz there may be an easier way if that is what you're doing.
gobosox
08-15-2007, 02:13 PM
Hey, looks good. Well i guess ill have to wait till i finish up here to test it out but should work!
Ok, yes that is exactly what im doing, its a navigation set up in a website. what did you have in mind? And if i could do it all in the actions frame that would be great. Just trying to get a fundamentally sound one under my belt, there are always hack ways around the AS but im going to be stubborn this time.
Thanks!
Webjedikungfu
08-15-2007, 03:28 PM
You could always just go all out and make it all come in dynamically from your server, text, pics, and all. Using a mixture of XML nodes and dynamically created movieclips. Then code each movieclip button separately to bring in a myriad of different stuff to make each page different.
But I know nothing of that stuff. ;) Takes a lot of understanding and trial and error.
gobosox
08-16-2007, 08:09 AM
Hey thanks web, everything works perfectly. One question, now, is there a way to add a delay to the function? Where if one_mc is clicked, and the screen is up, it waits for the screen to come down before the page is loaded on top? Haven't had a chance to look at that yet, didnt know if there was a simple solution......
Webjedikungfu
08-16-2007, 09:42 AM
I'm not to sure exactly what you are asking.
Do you mean you don't like how a user can tap one_mc quickly to make projScreen flip out? You want a one tap smoother thing?
page is loaded on top
What page? You mean content showing inside of projScreen when it comes down?
gobosox
08-19-2007, 10:20 AM
ok, so everything is working fine with the screen. Basically now, there are going to be 5 pages that will load over the screen (projector like). Now my question is: When the user gets to the site and after the intro, the screen will initially be up. When a button is clicked it will come down, but i need to either add to the function or the button, so if the screen is down it(a page) loads immediately, if it has to come down, there is a delay before the page loads to let the animation of the screen run.
Any thoughts?
Secondly, is there a way to add a more than just the function to the onRelease of a movie clip. Like add a function, then a gotoAndPlay also so it plays the function then loads the page?
Webjedikungfu
08-19-2007, 11:17 AM
Hey gobosox,
Yes you can add a layer inside of the "projScreen" movieclip. On this new layer create a keyframe at the exact frame where the screen animation is at full expansion. Put a movieclip in that frame on new layer and the movieclip on that frame won't start til the screen comes down fully.
On this keyframe(full expansion) inside of "projScreen" you can place all the actionscript you want to run anywhere in the movie. Whether it be inside of "projScreen" or not. You can command the _root scene to do something at that point if you wish. Play a sound, etc...
Make sense? If you look at my first image sent in this thread you'll see a layer named "menu btn..". That is where you place your page movieclip to run only when it should.
~Adam
gobosox
08-19-2007, 11:44 AM
ok, now if the button controls the up and down of the screen, if the screen is up, wont it not play that movie clip because it wont load till the end keyframe of the screen?
gobosox
08-19-2007, 12:27 PM
ok, now im confused.
Here is the call for the buttons
btnAssessment.onRelease = _root.toggleScreen;
_root.projScreen.mc_mainPages.gotoAndPlay("assessment");
and here is the function which is on the main timeline.
function toggleScreen():Void {
if (projScreen.videoState == false) {
projScreen.gotoAndPlay("expand");
} else if (projScreen.videoState == true) {
projScreen.gotoAndStop("down");
}
}
The function is working fine, the problem is with loading the pages? No clue why its not working. Is there anyway to add something to the function?
Webjedikungfu
08-19-2007, 12:51 PM
ok, now if the button controls the up and down of the screen, if the screen is up, wont it not play that movie clip because it wont load till the end keyframe of the screen?
No cuz if the screen is up the keyframe inside "projScreen" where the movie clip lives would not be in existance anymore.
"mc_mainPages" is only in existance and see-able when screen is fully expanded out. So on your screen "retract up" animation inside of "projScreen" make sure the "mc_mainPages" movie clip frame goes away.
gobosox
08-20-2007, 11:48 AM
Hey web, so i did what you suggested and it doesnt work, the code is two posts up, is the syntax correct for the button? It loads the frame but wont gotoAndPlay at all in the mainPages mc? Any thoughts? Arrrggggghh!!
Webjedikungfu
08-20-2007, 10:54 PM
Hey gobosox,
Private message me.
I think the best & fastest way for us to go forward is to give me your current .fla file in private, and I'll send it back with new stuff and comments on what I did.
And it will help me see exactly what you are attempting to make happen better.
Let me know if that'll work, cuz now I'm confused.:eek: :)