clear DNS cache
for win
in command line:
ipconfig /flushdns
for mac
in terminal
dscacheutil -flushcache
as3 embed youtube player fullscreen problem
stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHandler);
function fullScreenHandler(e:FullScreenEvent) {
if(!e.fullScreen){ //you just returned back to normal
topMC.addChild(player);
player.setSize(640, 360)
}else{ //you just entered full screen mode
xxx.addChild(player);
player.setSize(stage.stageWidth, stage.stageHeight)
}
};
mc change depth to top
this.setChildIndex(mc, this.numChildren-1)
as3 sound fade in fade out
// Initialize sound variables
var so:Sound = new Sound();
var sc:SoundChannel;
var fadeInIncr = 0.1;
var sAmbienceVol:SoundTransform = new SoundTransform(fadeInIncr, 0); // 1=vol, 0=pan
var soundFadeOutTimer:Timer = new Timer(100,10);
var soundFadeInTimer:Timer = new Timer(100,10);
soundFadeOutTimer.addEventListener("timer", soundFadeOut);
soundFadeInTimer.addEventListener("timer", soundFadeIn);
soundFadeOutTimer.addEventListener(TimerEvent.TIMER_COMPLETE, soundOutComplete);
soundFadeInTimer.addEventListener(TimerEvent.TIMER_COMPLETE, soundInComplete);
loadMusic()
var soundFadeInSwitch:Boolean =false;
var soundFadeOutSwitch:Boolean =true;
function loadMusic():void{
so = new Sound(new URLRequest("xxx.mp3"));
so.addEventListener(Event.COMPLETE, soundLoadComplete);
so.addEventListener(ProgressEvent.PROGRESS, soundprogressHandler);
}
function soundprogressHandler(event:ProgressEvent):void {
var loadTime:Number = event.bytesLoaded / event.bytesTotal;
var loadPercent:uint = Math.round(100 * loadTime);
sound_mc.loaded_txt.text =loadPercent + "%";
}
function soundLoadComplete(event:Event):void {
sound_mc.loaded_txt.text ="";
startMusic();
sc = so.play(0, 1, sAmbienceVol);
}
function stopMusic():void{
soundFadeOutSwitch=false;
soundFadeOutTimer.reset();
soundFadeOutTimer.start()
}
function startMusic():void{
soundFadeInSwitch=false;
soundFadeInTimer.reset();
soundFadeInTimer.start()
}
function soundFadeOut(e:TimerEvent){
trace(fadeInIncr);
if(fadeInIncr>0){
fadeInIncr -= 1/10;
}else{
fadeInIncr=0;
soundFadeOutTimer.stop();
}
sAmbienceVol = new SoundTransform(fadeInIncr, 0);
sc.soundTransform = sAmbienceVol;
}
function soundFadeIn(e:TimerEvent){
trace(fadeInIncr);
if(fadeInIncr<=1){
fadeInIncr += 1/10;
}else{
fadeInIncr=1;
soundFadeInTimer.stop();
}
sAmbienceVol = new SoundTransform(fadeInIncr, 0);
sc.soundTransform = sAmbienceVol;
}
function soundInComplete(e:TimerEvent):void {
sAmbienceVol = new SoundTransform(1, 0);
sc.soundTransform = sAmbienceVol;
soundFadeInSwitch=true;
}
function soundOutComplete(e:TimerEvent):void {
sAmbienceVol = new SoundTransform(0, 0);
sc.soundTransform = sAmbienceVol;
soundFadeOutSwitch=true;
}
Firefox/Chrome Flash TextField can't type chinese
html wmode -> Window ->done!
as3 sound length and position
var so:Sound = new Sound();
var sc:SoundChannel;
so = new Sound(new URLRequest("xxx.mp3"));
so.addEventListener(Event.COMPLETE, soundLoadComplete);
sc = so.play();
function soundLoadComplete(event:Event):void {
}
sc.position //song right now position
so.length //song total length
AS3 Delete all child from MC
while (mc.numChildren) {
mc.removeChildAt(0);
}
as3 call javascript function
import flash.external.ExternalInterface;
ExternalInterface.call("your_javascript_function","params1","params2","etc");
javascript show or hide div
<script language="javascript">
function toggle() {
var ele = document.getElementById("toggleText");
if(ele.style.display == "block") {
ele.style.display = "none";
}
else {
ele.style.display = "block";
}
}
</script>
<div id="toggleText" style="display: none">
<h1>test</h1>
</div>
call as3 function from javascript use swfobject
JS code
var flashObj = document.getElementById("flash_id");// must have real ID you passed to SWFObject
flashObj.getFromJavaScript();
AS3 code
import flash.external.ExternalInterface;
ExternalInterface.addCallback("getFromJavaScript", anActionScriptMethod);
function anActionScriptMethod():void{
//do something
}
get page info from facebook graph api
import com.adobe.serialization.json.JSON;
Security.loadPolicyFile("http://graph.facebook.com/crossdomain.xml");
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("http://graph.facebook.com/http://www.google.com/"));
myLoader.addEventListener(Event.COMPLETE, Complete);
}
function Complete(e:Event):void{
trace(JSON.decode(e.target.data));
}
use json get it