Tuesday, 24 December 2013

Working adobe flash archives with flex sdk

If you are from who likes to work with flash but for some reasons you have to work with flex, no problem you can add the flex sdk to your flash archive and you can start to work.

Go to file-> ActionScript settings
 Browse flex sdk

 Browse for core

 And now you're ready to work with it

 Create a class and run it:

package  {
   
    import flash.display.MovieClip;
   
    [SWF(frameRate="30", backgroundColor="#000000")]
    public class Example extends MovieClip {
       
       
        public function Example() {
            // constructor code
            init();
        }
        private function init():void{
            trace("Running with flex sdk");
        }
    }
   
}

If everything is alright it will display the message: "Running with flex sdk".

Sunday, 15 December 2013

Eliminate background given two images, reduce reds to get transparency -> AS3

package  {
    import flash.display.Sprite;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.geom.Rectangle;
    import flash.geom.Point;
   
    public class MergeBitmap extends Sprite {
         //Given 2 images (one normal the other the mask in alphachannel) merge 'em and to get an alphachannel image (an image without background), Useful if you want to eliminate bgr.

         public function merge (img:BitmapData, alphachannelMask:BitmapData) :Bitmap
        {
            var merged:BitmapData = new BitmapData(img.width, img.height, true, 0);
            var rect:Rectangle = new Rectangle(0, 0, img.width, img.height);
            merged.copyPixels(img, rect, new new Point());
            merged.copyChannel(alphachannelMask, new Rectangle(0, 0, img.width, img.height), new Point(), BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA);
            return new Bitmap(merged);
        }
       
        public function FromRedToTransparent( original:BitmapData ):BitmapData {//Diminish reds in image eliminate blacks results transparency and a black shape
            var bmd:BitmapData = new BitmapData( original.width, original.height, true, 0x00000000 );
            bmd.copyChannel( original, bmd.rect, new Point(), BitmapDataChannel.RED,BitmapDataChannel.ALPHA );
            return bmd;
        }

    }
   
}

Friday, 13 December 2013

Time remaining & Time lapsed -> js

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Counter example</title>
<script>
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var dayarray= new Array("Sun","Mon" ,"Tue","Wed","Thu","Fri","Sat");
//Event Informations
//Xmas 2013
var year = 2013;          
var month = 11;              
var day = 25;//(1..31)              
var hour = 0;//(0..24)              
var minute = 0;          
var second = 0;  
var xmas = new Date(year,month,day,hour,minute,second);
function TimeCounter(){
    var now = new Date();
    if(now.getYear() < 1900)
        yr = now.getYear() + 1900;  
   
     if(now >= xmas){//Days after xmas
     //Days lapsed xmas - Ascending time

     var todaym=now.getMonth()
     var todayd=now.getDate()
     var todayh=now.getHours()
     var todayday= dayarray[now.getDay()]
     var endday=dayarray[xmas.getDay()]
     var sec =  now.getSeconds();
    var min =  now.getMinutes();
    var hr = 24 -(hour - (now.getHours() -1));
    var todaystring=todayday +", "+todayd+" "+montharray[todaym]+" "+yr+" "+todayh+":"+min+":"+sec //see         https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
    var paststring=endday +", "+day+" "+montharray[month]+" "+year+" "+hour+":"+minute+":"+second

    var difference=(Math.round(  (Date.parse (todaystring) -Date.parse (paststring) ) / (24*60*60*1000) )*1)
      
     if(difference<0){
      dy=0
      }
     else{
      dy=difference
     }
  
    if(sec > 60){
        sec = (sec-60)%60;
        min++;
    }
    if(min > 60){
        min = (min-60)%60;
        hr++;  
    }
    if(hr > 23){
        hr = (hr-24)%24;
        //dy++;  
    }
        document.getElementById("TimeCounter").innerHTML =" + days "+ dy +"                   " +"     hours "+ hr +"           minutes " + min +"'           seconds "+ sec+"''   after xmas 2013          "  ;
     }
     else{//Days before xmas
     //Days remaining xmas - Descending time
      var sec = second - now.getSeconds();
      var min = minute - now.getMinutes();
      var hr = hour - now.getHours();
      var dy = day - now.getDate();
      var mnth = month - now.getMonth();
      var yr = year - yr;
      var daysinmnth = 32 - new Date(now.getYear(),now.getMonth(), 32).getDate();//How many days it has the month
    if(sec < 0){//if second is less than zero diminish minute
        sec = (sec+60)%60;
        min--;
    }
    if(min < 0){//if minute is less than zero diminish hour
        min = (min+60)%60;
        hr--;  
    }
    if(hr < 0){//if hour is less than zero diminish day
        hr = (hr+24)%24;
        dy--;  
    }
    if(dy < 0){//if day is less than zero diminish month
        dy = (dy+daysinmnth)%daysinmnth;
        mnth--;  
    }
    if(mnth < 0){//if month is less than zero diminish year
        mnth = (mnth+12)%12;
        yr--;
    }  
    document.getElementById("TimeCounter").innerHTML =" - days "+ dy +"                   " +"     hours "+ hr +"           minutes " + min +"'           seconds "+ sec+"''  for xmas  2013         "  ;
    
     }
    
    ID = setTimeout("TimeCounter()", 1000);
}
window.onload=TimeCounter;
</script>
</head>

<body>
 <span id="TimeCounter"></span>
</body>
</html>