Solved

insert an AS3 code to a Close Button

Posted on 2010-11-11
8
1,032 Views
Last Modified: 2012-05-10
I am trying to create a close button on a transparent flash movie and it is not working. My movie is playing in an html page in its own window. I inserted a button in a layer and add this code :

. When the button is pressed I want to close the flash movie. How do I do this?

Thanks in Advance!
this.close_btn.addEventListener(MouseEvent.CLICK,closeall);
function closeall(event:MouseEvent):void
Fscommand ("quit")

Open in new window

0
Comment
Question by:lomac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34117520
try this:

this.close_btn.addEventListener(MouseEvent.CLICK,closeall);  
function closeall(event:MouseEvent):void  
ExternalInterface.call("javascript:window.close();");
}

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com 
0
 

Author Comment

by:lomac
ID: 34118565
Many thanks for your reply, I have these errors

Scene 1, Layer 'Actions', Frame 300, Line 2      1126: Function does not have a body.
ComponentShim (Compiled Clip), Line 1      5000: The class 'fl.controls.Button' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.

what should i do?
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34118816
Try this:

// the function that runs when after button was clicked
function closeall(e:MouseEvent):void {
  var req:URLRequest = new URLRequest("javascript:window.close();");
  navigateToURL(req, "_self");
}
close_btn.addEventListener(MouseEvent.CLICK,closeall);

The error that you forwarded has nothing to do with the code i provided.
To debug that you need to share some more of your code snippet.

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com 
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lomac
ID: 34119503
here is my flash movie
simple-transparent-ads.zip
when i click on close button, i want to close only the flashmovie
not the entire window of the web page where it's included
thanks for your help
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34131178
Hi,
There is no such direct way.
You can call a javascript function from flash which will hide the flash object.

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com 
0
 

Author Comment

by:lomac
ID: 34131239
Good evening,
After many research, i confirm that there is no direct way; but, please, how could i do this ?
is there any code to add in the html?
warm regards
0
 
LVL 17

Accepted Solution

by:
deepanjandas earned 500 total points
ID: 34133395
Hi,
The best way is to use SWFObject Javascript to embed flash.

Now that your flash gets embed into a div ('myContent' as per the example provided in the above link), you can control the visibility of the dic using getElementById.

Now in html write a javascript function like this:
function hideFlash(){
document.getElementById('myContent').style.visibility='hidden';
// check this for more info: http://www.webreference.com/js/tips/001215.html
}

Then call this function from flash using ExternalInterface.
ExternalInterface.call('hideFlash');

Please keep a note:
The AllowScriptAccess should be set to 'always'. Check this for more info.

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com 
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34245673
Did the solution helped you. If yes, kindly mark this as solved.

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com 
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question