as3 Two-dimensional array sort

2011年12月22日 星期四 by Hu, Ching-Hsiang

var best_arr:Array=new Array(new Array(1,'abc'),new Array(9,'abc'),new Array(1,'abc'),new Array(10,'abc')); //best_arr.sortOn(Array,Array.NUMERIC ); best_arr=newSort(best_arr,0) trace(best_arr); function newSort(arr:Array,soryBy:int):Array{ var temp_arr:Array=new Array(); var sort_arr:Array=new Array(); var i:int; for(i=0;i<arr.length;i++){ sort_arr.push({number:arr[i][soryBy],oldsort:i}); } sort_arr.sortOn('number',Array.NUMERIC |Array.DESCENDING ); for(i=0;i<sort_arr.length;i++){ temp_arr[i]=arr[sort_arr[i].oldsort]; } return temp_arr }

Filed under having 0 意見  

as3 facebook init warning!!

2011年12月20日 星期二 by Hu, Ching-Hsiang

http://patw.idv.tw/blog/archives/315

Filed under having 0 意見  

as3 facebook application new login permission

2011年12月16日 星期五 by Hu, Ching-Hsiang

use GraphAPI 1.8.1
Facebook.login(handleLogin,{perms:"email"});
replace to
Facebook.login(handleLogin,{scope:"email"});

Filed under having 0 意見  

as3 facebook application double scroll bar

by Hu, Ching-Hsiang

http://www.hyperarts.com/blog/facebook-iframe-apps-getting-rid-of-scrollbars/

Filed under having 0 意見  

as3 search string or array

2011年10月2日 星期日 by Hu, Ching-Hsiang

var a:String="gamaniasen";
var b:String='sen';
var i:int
var Len:int=a.length;
var space:int=b.length;

for(i=0;i if(a.slice(i,i+space)==b){
trace("true")
}
}

Filed under having 0 意見  

as3 A depth higher then B

2011年9月27日 星期二 by Hu, Ching-Hsiang


this.setChildIndex(A,this.getChildIndex(B));

Filed under having 0 意見  

as3 array random sort

2011年9月22日 星期四 by Hu, Ching-Hsiang


var temp_array:Array = new Array(1,2,3,4,5)
temp_array.sort(randomSort)
trace(temp_array )


function randomSort(a:Object, b:Object):Number{
var r:Number = Math.random() - Math.random();
if(r >0)return 1;
if(r< 0)return -1; return 0; }

Filed under having 0 意見  

as3 load XML

2011年8月25日 星期四 by Hu, Ching-Hsiang

XML
<?xml version="1.0"?>
<config>
<api><![CDATA[http://xxx]]></api>
<secure><![CDATA[1]]></secure>
</config>


AS

function loadXML():void{
var request_show:URLRequest = new URLRequest("frame/config.xml");
var loader_php:URLLoader = new URLLoader(request_show);
loader_php.addEventListener(Event.COMPLETE,search_Complete);
loader_php.load(request_show);
}
function search_Complete(e:Event):void {
configXML = XML(e.target.data);
trace(configXML.api[0].text());//output: http://xxx
trace(configXML.secure[0].text());//output: 1
}

Filed under having 0 意見  

as3 unixtime

2011年8月21日 星期日 by Hu, Ching-Hsiang


var myDate = new Date();
trace(myDate);
var unixTime = Math.round(myDate.getTime()/1000);
trace("Unix Time: "+unixTime);

var dateNew = new Date();
dateNew.setTime(unixTime);
trace(dateNew);

Filed under having 0 意見  

as3 TLFTextfield's text Always update, memory can't be release

2011年8月10日 星期三 by Hu, Ching-Hsiang

TLFTextfield的文字如果不斷更新~~記憶體不會被釋放
if TLFTextfield's text Always update, memory can't be release

Filed under having 0 意見  

as3 textfield alpha

2011年7月25日 星期一 by Hu, Ching-Hsiang


txt.blendMode = BlendMode.LAYER;

Filed under having 0 意見  

AS3 distance between two points

2011年7月22日 星期五 by Hu, Ching-Hsiang

way 1

function DistanceTwoPoints(x1:Number, x2:Number, y1:Number, y2:Number):
Number {
var dx:Number = x1-x2;
var dy:Number = y1-y2;
return Math.sqrt(dx * dx + dy * dy);
}

way 2

var pt1:Point = new Point(circle1.x, circle1.y);
var pt2:Point = new Point(circle2.x, circle2.y);
var distance:Number = Point.distance(pt1, pt2);

Filed under having 0 意見  

as3 eventListener function with parameter

2011年6月2日 星期四 by Hu, Ching-Hsiang


mc.addEventListener(Event.COMPLETE,function(e : Event) : void{LoadedComplete(e, 'test' ,true);});
function LoadedComplete(e:Event,txt:String,switch:Boolean ):void{

}

Filed under having 0 意見  

css hack ie6, ie7, ie8, firefox

2011年5月18日 星期三 by Hu, Ching-Hsiang

css hack

Filed under having 0 意見  

clear DNS cache

2011年5月16日 星期一 by Hu, Ching-Hsiang

for win
in command line:

ipconfig /flushdns


for mac
in terminal

dscacheutil -flushcache

Filed under having 0 意見  

as3 embed youtube player fullscreen problem

by Hu, Ching-Hsiang


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)
}
};

Filed under having 0 意見  

mc change depth to top

by Hu, Ching-Hsiang


this.setChildIndex(mc, this.numChildren-1)

Filed under having 0 意見  

as3 sound fade in fade out

2011年5月15日 星期日 by Hu, Ching-Hsiang


// 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; }

Filed under having 0 意見  

Firefox/Chrome Flash TextField can't type chinese

2011年5月10日 星期二 by Hu, Ching-Hsiang

html wmode -> Window ->done!

Filed under having 0 意見  

as3 sound length and position

by Hu, Ching-Hsiang


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

Filed under having 0 意見  

AS3 Delete all child from MC

2011年5月5日 星期四 by Hu, Ching-Hsiang


while (mc.numChildren) {
mc.removeChildAt(0);
}

Filed under having 0 意見  

as3 call javascript function

2011年5月3日 星期二 by Hu, Ching-Hsiang


import flash.external.ExternalInterface;
ExternalInterface.call("your_javascript_function","params1","params2","etc");

Filed under having 0 意見  

javascript show or hide div

by Hu, Ching-Hsiang

<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>

Filed under having 0 意見  

Detect click like button use javascript

by Hu, Ching-Hsiang

Link

Filed under having 0 意見  

call as3 function from javascript use swfobject

by Hu, Ching-Hsiang

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
}

Filed under having 0 意見  

get page info from facebook graph api

2011年5月2日 星期一 by Hu, Ching-Hsiang


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

Filed under having 0 意見  

5005: unknown error optimizing byte code

2011年3月30日 星期三 by Hu, Ching-Hsiang

computer -> properties -> advanced -> environment vars -> then make a new var like this

JAVA_TOOL_OPTIONS

and its value

-Xmx1024M

我的電腦 > 右鍵內容 > 進階 > 環境變數 > 系統變數"新增"變數值 > 名稱 JAVA_TOOL_OPTIONS > 值 -Xmx1024M
(1024 or 512..256..128)

Filed under having 0 意見  

Tween function

2011年3月29日 星期二 by Hu, Ching-Hsiang


Linear.easeNone
Back
Bounce
Circ
Cubic
Elastic
Expo
Quart
Quint
Sine
(xxx.easeIn, xxx.easeOut, xxx.easeInOut)

Filed under having 0 意見  

AS3 fullscreen or not

by Hu, Ching-Hsiang

stage.displayState=StageDisplayState.FULL_SCREEN;
stage.displayState=StageDisplayState.NORMAL;

Filed under having 0 意見  

http can't find index.html??

2011年3月27日 星期日 by Hu, Ching-Hsiang

ftp root folder -> .htaccess

DirectoryIndex index.htm index.html index.php

Filed under having 0 意見  

google tracking

by Hu, Ching-Hsiang

in html

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
function GAPageView(url){_gaq.push(['_trackPageview', url]);}
function GAEventTrack(category, action, label){_gaq.push(['_trackEvent', category, action, label]);}
</script>


in as

tracking page view
GATracking.trackPageview("/index");

tracking event
GATracking.trackEvent("/index", "action", "做了啥");


GATracking.as -> author jacky

Filed under having 0 意見  

compare round, floor, ceil

by Hu, Ching-Hsiang

int();無條件捨去
Math.round();四捨五入
Math.floor();無條件捨去
Math.ceil();無條件進位

Filed under having 0 意見  

SWF get parameter from html

2011年3月26日 星期六 by Hu, Ching-Hsiang

in js
<script type="text/javascript">
  function $G(){
   var Url=top.window.location.href;
   var u,g,StrBack='';
   if(arguments[arguments.length-1]=="#")
    u=Url.split("#");
   else
    u=Url.split("?");
   if (u.length==1) g='';
   else g=u[1];

   if(g!=''){
    gg=g.split("&");
    var MaxI=gg.length;
    str = arguments[0]+"=";
    for(i=0;i<MaxI;i++){
     if(gg[i].indexOf(str)==0) {
      StrBack=gg[i].replace(str,"");
      break;
     }
    }
   }
   return StrBack;
  }
 </script>

embedSWF("index.swf?id="+$G("param") , "flashcontent" , "100%" , "100%" , "10.0.0.0");


in html
index.swf?param=xxx

in as3
loaderInfo.parameters.param;
can get xxx

Filed under having 0 意見  

bitmap to png or jpg

by Hu, Ching-Hsiang

import com.adobe.images.PNGEncoder;
import com.adobe.images.JPGEncoder;

var _bitmapData:BitmapData = new BitmapData(mc.width,mc.height);
_bitmapData.draw(mc);
var _byte:ByteArray = PNGEncoder.encode(_bitmapData);
//var _byte:ByteArray = JPGEncoder.encode(_bitmapData);
var _file:FileReference = new FileReference();
_file.save(_byte ,"file.png");

Filed under having 0 意見  

Facebook Graph api fql.query cookie fix

by Hu, Ching-Hsiang


Facebook.fqlQuery("SELECT type, page_id FROM page_fan WHERE uid= "+uid+
" and page_id="+pageID+" and "+randRange(0,100), callbackfunction);


send random int!!!

Filed under , having 0 意見  

Check Email Format

by Hu, Ching-Hsiang


function isValidEmailAddress($str:String):Boolean {
return (($str == findValidEmailAddress($str)) ? true : false);
}

function findValidEmailAddress($str:String):String {
var pattern:RegExp = /\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b/gi;
var result:Object = pattern.exec($str);
return ((result == null) ? "" : result[0]);
}

Filed under having 0 意見  

AS3 Performance note

2011年3月25日 星期五 by Hu, Ching-Hsiang

Object pool        >  new Sprite();
array[0]='string' > array.push('string');
switch case        > if else
*                       > /
for(i=0;i<j;i++) > for(var i=0;i<array.length;i++)

p.s remove listener(enterframe, mousemove, timer) when object remove on stage

Filed under having 0 意見  

AS3 tabIndex

by Hu, Ching-Hsiang

txt.tabIndex=1//(1~65535)

Filed under having 0 意見  

AS3 TextField input Number

2011年3月23日 星期三 by Hu, Ching-Hsiang

txt.restrict="0-9";

Filed under having 0 意見  

AS3 setTimeout and Timer

2011年3月21日 星期一 by Hu, Ching-Hsiang

setTimeout(function(){

}, 5000);


var myTimer:Timer= new Timer(5000, 1);
myTimer.addEventListener("timer", timerHandler);
myTimer.start();

function timerHandler(event:TimerEvent):void {
trace("timerHandler: " + event);
}

Filed under having 0 意見  

AS3 Random Range

2011年3月19日 星期六 by Hu, Ching-Hsiang


function randRange(minNum:Number, maxNum:Number):Number {
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}

Filed under having 0 意見  

AS3 on resize

2011年3月17日 星期四 by Hu, Ching-Hsiang

stage.addEventListener(Event.RESIZE, resizeHandler);
function resizeHandler(e:Event):void{
reSize();
}
function reSize():void{

}
reSize();

Filed under having 0 意見  

AS3 Open URL

2011年3月13日 星期日 by Hu, Ching-Hsiang

navigateToURL(new URLRequest("http://www.google.com.tw"), '_blank');

'_self' also

in Chinese case
navigateToURL(new URLRequest(encodeURI("http://www.google.com.tw?中文")), '_blank');

js
var js:URLRequest=new URLRequest();
js.url="javascript:window.open('award.html','popper1','width=540,height=360');newWindow.focus(); void(0);";

pop_btn.addEventListener(MouseEvent.CLICK,openPopUp);

function openPopUp(evt:MouseEvent):void{
navigateToURL(js,'_self');
}

Filed under having 0 意見  

Facebook Graph API Login, PostData

2011年3月12日 星期六 by Hu, Ching-Hsiang

facebook init

Facebook.init('App ID', initLogin);
function initLogin(response:Object, fail:Object):void {//facebook init

}


facebook login

Facebook.login(handleLogin,{perms:"user_birthday,read_stream,publish_stream,user_photos"});
function handleLogin(response:Object, fail:Object):void {//facebook login
if(response!=null){
Facebook.api('/me', onMyInfoLoaded);
}
}

load facebook info and post data

function onMyInfoLoaded(response:Object,fail:Object):void {//facebook info success
if(response!=null){
var params:Object = {
source: 'http://xxx.jpg',
picture: 'http://xxx.jpg',
message: 'text',
link: 'http://adidas-oba2011-2.youthwant.com.tw',
name: 'Adidas is all in',
caption: '內容',
description: '內容'
};
Facebook.postData('/me/feed', requestHandler, params);
}
}
function requestHandler(result:Object, fail:Object):void{
if (result != null){
if (result.error_msg != null){
//error
}else{
//success
}
}
if (fail != null){
//error
}
}

Adobe Flash Player Debug

2011年3月10日 星期四 by Hu, Ching-Hsiang

always for facebook application debug
Debug Flash Player
http://www.adobe.com/support/flashplayer/downloads.html

Filed under having 0 意見  

Get Params From SWF

by Hu, Ching-Hsiang

xxx.com
Loading
loaderInfo.parameters.id
in as can get http://yoururl.com/xxx.swf?id=xxx

Filed under , having 0 意見  

Crossdomain Load Image as Bitmap

by Hu, Ching-Hsiang

var loaderContext:LoaderContext = new LoaderContext ();
loaderContext.checkPolicyFile = true;
loaderContext.applicationDomain = ApplicationDomain.currentDomain;
pic_loader.load(new URLRequest("url"), loaderContext);

Filed under having 0 意見  

Social Website URL Share

by Hu, Ching-Hsiang

twitter:
http://twitter.com/?status=xxx http://xxx

plurk:
link: http://plurk.com/?status=www.google.com(xxx)
image: http://plurk.com/?status=http://xxx.jpg

facebook:
http://www.facebook.com/share.php?u=http://xxx

Filed under , having 0 意見  

AS3 Copy text to clipboard

by Hu, Ching-Hsiang

System.setClipboard(source.text);

Filed under having 0 意見