I am making a flash file, I am using Adobe Flash CS6 to make it and so using ActionScript 3.0 for coding, I have a kind of "a link" called "About", it should move the flash to a frame that has the "About" content which number is 290 here in my case.
Here is my code for clicking on the "About" button:
import flash.events.MouseEvent;
var frameNumber:int;
var counter:int;
function onClick3(event:MouseEvent):void
{
if (counter%2 == 0)
{
frameNumber = currentFrame;
gotoAndStop(290);
}
else
{
gotoAndStop(frameNumber);
}
counter++;
}
aboutButton.addEventListener(MouseEvent.CLICK, onClick3);
This should display the "About" frame on even clicks (starting from zero) and go back to the frame that "About" was clicked from on odd clicks, like this:
Click on "About" --> Show About.
Another Click on "About" --> Hide About and go back to the calling frame.
Another click on "About" --> Show About.
And so on..
It works well for moving between a frame and the "About" frame (290), but the problem is that I have a "Next" and "Previous" buttons too, but when I come back from the "About" page, the whole flash freezes and nothing work except the "About" button, so what is the problem here ? What can solve this ?
And if there exist, is there a way to display my "About" section as a pop-up message in flash ?
Related
Alright, I have a difficult problem "for me" , I'm a beginner in Adobe Flash CS6.
The Problem
I can't make the button works for all frame. I was unable to click once I jump to another frame or scene.
The Explaination
I'll explain more detail what I'm trying to do with the button.
I Have have a button which is named "Back to Menu" that placed in "Play" Scene, the button supposed to get the user back to the menu.
"Main Menu" Scene (1 Frame)
"Play" Scene (10 Frame)
The code is placed on frame 1, in the "Play" Scene and the code used is :
backtomenu.addEventListener(MouseEvent.CLICK, backmenuClick);
function backmenuClick(ev:MouseEvent):void
{
gotoandPlay ("Main Menu");
}
So, at the Main Menu there is 9 button, each button from the "Main Menu" Scene will bring to the different frame at the "Play" Scene. The backtomenu button works fine when I click the button that take me to the frame 1 in "Play Scene", but whenever I click the button that direct me from "Main Menu" Scene to frame 2 , 3 or 4 in "Play" Scene, the backtomenu button won't work.
Is there any other way to make the code readable to all frame? or make a universal button? Because I know the code wasn't read when I was at the 2nd Frame in the "Play" Scene. do I have to make a different code for each frame? if that so, that's insane.
You can put your "Back to Menu" button on a new layer with 1 keyframe & 9 frames to cover the whole "Play" scene.
Your "backtomenu.addEventListener" code needs to be placed in the keyframe of the new layer.
i'm working on a AS3 ball game, currently i have 2 scenes home and baseball. home has a button which sends the player to the baseball which has a little ball catching game. the button in question is on the home page, it works fine when the FLA loads and you have to click the reb button to load the game but once the game over it sends the player back to the home and the button doesnt want to load.
You'll notice that when you return to the home scene, the output continues to trace "return". This is because you are never removing your Event.ENTER_FRAME listener for exit or resetting the Score to 0.
function exit (evt:Event) : void
{
if (Score == 2)
{
Score = 0;
trace("return");
clearInterval(interval);
removeEventListener(Event.ENTER_FRAME, exit); // <--- added line
removeEventListener(Event.ENTER_FRAME,Ballgame);
gotoAndPlay(1,"home");
}
}
This will fix your issue with the button not working in your home scene, however, you'll want to add some code to clean up the display list (as it will still show all of the baseballs that you generated on the ballgame scene).
I have a menu with 4 button, for switch to other content page, and all of it had this code:
function chuyenhome(e:MouseEvent):void{
homect.addEventListener(Event.ENTER_FRAME, nexttohome);
btn_home.gotoAndStop(15);
if (btn_about.currentFrame == 15){
btn_about.gotoAndPlay(16);
}
if (btn_menu.currentFrame == 15){
btn_menu.gotoAndPlay(16);
}
if (btn_contact.currentFrame == 15){
btn_contact.gotoAndPlay(16);
}
homect.gotoAndPlay(31);
}
function nexttohome(e:Event):void{
if (homect.currentFrame>=homect.totalFrames){
MovieClip(root).gotoAndStop(4);
}
}
This is menu HOME. 3 other menu ABOUT, BLOG, CONTACT button is using the same code, but renamed function. It work fine if I click only 2 menu button. But when I try to click the third menu, it's going crazy. For example, when I click at HOME and ABOUT, it switch to HOME page and ABOUT page with no problem, no matter if I click it for thousand times. It work fine, but when I try to click at CONTACT, then... it show up HOME page, I re-click CONTACT, it show up ABOUT... and so on. It's crazy. Sorry about my English. I'm using Flash CS4 and AS3. Thanks!
You have to not add multiple event listeners to one MC. See, if all the other functions are this one copypasted with altered frames, then each of them adds an enter frame listener. These are cumulative, thus calling homect.addEventListener(Event.ENTER_FRAME, nexttohome); twice will result in two calls to nexttohome per frame. Probably you can avoid this listener altogether by putting code to the timeline of homect movie clip on the last frame, to call stop(); MovieClip(root).gotoAndStop(4);
I have a swf embedded into a site, and I want the swf to be clickable so when you click on it it goes to another page. I tried wrapping the whole flash object in tags, and that makes it clickable but the biggest problem I'm having is when you roll over it with the mouse the pointer icon doesn't come up, it just looks like the regular arrow. I tried playing with the css and doing cursor:pointer, but it still doesn't work. Any suggestions? I can edit the .fla file and add some actionscript 2.0 to it, but I'm not sure what to add or where. I'd rather do it through html or css, but if I have to do it in flash that's ok too.
Also, I have an invisible button over the whole thing called, MYbtn
i think that the best solution is to add some code in your fla. Open it with Flash and locate the timeline. Right-click on the first frame, "Actions" and you can enter your code.
You can divide your problem in two point:
Display a link cursor when the mouse
is over
Move your browser to your
url when the user press the mouse
button
For the first problem this code should do the work:
this.buttonMode = true;
For the second problem:
import flash.events.MouseEvent;
import flash.external.ExternalInterface;
this.addEventListener(MouseEvent.CLICK, function(evt:MouseEvent):void{
ExternalInterface.call("window.location.href = 'http://www.google.com'");
});
I haven't checked with Flash but this should work
If you have access to the .fla file, why don't you just edit it so that clicking anywhere on the screen redirects you to a new page? You can create an invisible button or something and use some actionscript to make it move people to a new page. I'm not exactly sure how you do it, but I've definitely made links in SWF files before and it's definitely possible.
The cursor should come up on most browsers , although I still haven't managed to get it to work on Chrome for Mac.
this.mouseEnabled = true;
this.buttonMode = true;
addEventListener(MouseEvent.CLICK , mouseClickHandler );
function mouseClickHandler(event:MouseEvent):void
{
navigateToURL( new URLRequest("your location"));
}
Check the docs for more info on navigateToURL
http://www.adobe.com/livedocs/flex/2/langref/flash/net/package.html
I am new to Flash.
I am using Adobe Flash CS3 to create simple animations (images moving between keyframes).
It produces a SWF file that I put on a website.
I want the SWF file to be a link to a URL. How do you do that?
Thank you in advanced!
The same answer using AS3:
in the 1st frame that the invisible button appears, you should paste the following code:
myButton.addEventListener(MouseEvent.CLICK, linkToPage);
function linkToPage(e:MouseEvent):void{
var request:URLRequest = new URLRequest("your page here");
navigateToURL(request);
}
You should name the button instance 'myButton' (in the properties bar - the bottom-left input dialog). That should do the trick.
1st you have to create an invisible button. An invisible button is a button with only the HIT frame. Create a button that covers all your stage. It will appear in your stage as a blue-transparent shape. Just click it and press F9 to bring the 'actions' window.
After that, just paste the following code into the window:
on(release){
getUrl("here you put your url");
}
After that, just compile your code as AS2. I think that's the easiest way of doing this.