adding and removing from the page in ActionScript 3 - actionscript-3

I am using flash for the first time, I have a set of videos and image galleries, for users who are viewing it, I have created an Exit button so that the users can come out and go back to the menu. How do I go about doing this?
Thanks

Ok that you are looking for must be :
buttonExit.addEventListener(MouseEvent.CLICK, removePlayer);
function removePlayer( evt: MouseEvent ):void{
stage.removeChild(myVideoPlayer);
}
Is that what you need?

Related

Is it possible to add a Movieclip in a specific frame?

I add a menu button in the first frame (from an external class).
When i click it, it goes to the second frame, and it's still there.
Is it possible to add a mc in a specific frame?
I try to remove it while clicking on it but it gives me error...
Thanks!
You can remove your button by clicking like that :
function clicBouton(e:MouseEvent):void
{
gotoAndStop(2);
e.target.parent.removeChild(e.target);
}
You can use the addFrameScript() function to do so, as you already seem to have found out.
Here an example:
http://www.flashwork.biz/blog/?p=229
To tell you what you exact problem is you most likely need to post more details, but looking at your comment, you might have simply missed that addFrameScript() frame numbers start with 0 (zero) while frames in the IDE start at 1. Substract 1 from the frame number that the IDE shows.
An example:
If you want to add a script for frame 1 you should use
addFrameScript(0, onFrame1);

Having issues with event on click

I have a button instance named "instructionButton" and I'm trying to trace "Clicked." to the output when it is clicked as a test but I haven' been successful thus far. Is there something I'm missing?
I'm using code in Flash Pro 6
import flash.events.MouseEvent;
var clickedVar:String = "Clicked.";
var runVar:String = "mice running...";
trace(runVar);
function instructionOpen(event:MouseEvent):void
{
trace(clickedVar);
gotoAndPlay(255);
}
instructionsButton.addEventListener (MouseEvent.CLICK, instructionOpen);
And of course if there's a more simple way to approach this, all knowledge will be helpful.
Check instance name is provided or not in the property window for the button (click the button and go to menu 'Window->Properties' to open property window)
What name is mentioned in the property window for the button, should use the same instance name in action script coding. Ensure the spelling from both script(code) and property window instance name.
I don't really see anything wrong with your button code, but here's how i do mine in AS3, it may help :) Creating a simple function within the event listener, I use stopPropgation to prevent my button from clicking anything that may be below it in the flash file. ( say you have two buttons on top of one another, you'll click both instead of one)
instructionsButton.addEventListener(MouseEvent.CLICK, function(e){
e.stopPropagation();
trace("Clicked.");
gotoAndPlay(255);
});
This is one button, if you need say fifteen, let me know as I have a code sample I'll give you that i use to create a limitless amount of buttons and eventlistners using switch/case which has been a huge help to me :)
The only way this will not work is if you are not reaching this frame.
Try add this code on your first frame and tell me if this helping.

Button that only works once in flash actionscript 3.0

I have this collecting item game which u have to collect enough "stars" in order to acess a button. After I clicked the "star" button, it suppose to disappear and never appear again. However, when using this script, although the button disappear once I clicked it, when I returned to the frame after going to another frame, it appeared again! pls help!
star1.addEventListener(MouseEvent.CLICK,gotstar);
function gotstar(event:MouseEvent){
stars++;
star1.x = -500;
}
Are you coding on the frames themselves? If so every time you enter a frame it will run every piece of contained code, even if it has already ran once. A solution to this would be to use a document class to track the progress of the game.
you need to remove it from the stage if I understand.
try this instead of star1.x = -500;
stage.removeChild(star1);
star1.removeEventListener(MouseEvent.CLICK,gotstar);
star1.parent.removeChild(star1); in the click handler code (gotstar) should help
however posting your .fla file might be useful for better understanding

deep linking from xml to open function in Actionscript

I have general text in CDATA in my xml which is pulling in content into Flash. This is working well and I am able to add images this way too. What I need though is to wrap that image in an tag which, when clicked on will fire off a function in my Actionscript 2 to launch a video.
Could someone please tell me how I would go about this? Is there a better way than the way I am thinking right now?
Thanks.
I recently did this in AS3 but I found the AS2 way.
Tested it:
function myFunc(arg:String):Void
{
trace ("You clicked me!Argument was "+arg);
}
myTextField.htmlText ='Click Me!';
You just use a href that is set to asfunction with a function name and something to pass along.
See:
http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary073.html
Just to give credit I found the initial code at: blog.activepoison.com/?p=25.

making a swf a clickable link with the pointer icon

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