Flex AutoResizable Textarea

I’ve been quite busy those past weeks, working on some great projects and cool devices (Stay tune one will be available in all high tech shops soon).

Recently, I faced a very simple Flex problem. I had to work with a Textarea but I needed it to be autoresizable, and ALSO I had be able to set so constraints such as : maxchars displayed and maxheight. I had a quick look on the internet but I didn’t find a conponent fitting my needs. You may find some example using mx_internal properties but I try to avoid using this namespace…for many reasons.

Anyway, I crafted my own Autoresizable Textarea and share it to everyone who want to play with/improve/crash/burn/..etc it.


///////////////////////////////
// Author: Guillaume Nachury
//
//         Advanced Textarea
//
// -> Auoresize feature with
//             -> MaxChar limiter
//            -> MaxHeight limiter
///////////////////////////////

package
{
 import mx.controls.TextArea;

 public class AdvancedTextarea extends TextArea
 {

 private var _autoResize:Boolean =  false;
 private var _lineOffset:int = 5;
 public var fullText:String="";

 public function AdvancedTextarea(isAutoResize:Boolean=false)
 {
 super();
 _autoResize = isAutoResize;
 }

 //overrides        
 override public function set maxChars(i:int):void{
 super.maxChars = i;
 doValidations();
 }

 override public function set maxHeight(n:Number):void{
 super.maxHeight = n;
 doValidations();
 }

 override public function set text(s:String):void{
 //limit the number of chars if there's a limit
 fullText = s;
 if(super.maxChars>0 && s.length > super.maxChars){
 s = s.substring(0, super.maxChars)+"...";    
 super.text = s;
 }
 super.text = s;

 validateNow();
 doValidations();
 }

 private function doValidations():void{
 if(super.text != null && super.text.length >0){

 //limit the height if there's a limit
 if(!isNaN(super.maxHeight)){
 var textH:int = this.textField.measuredHeight+_lineOffset;
 if(textH > super.maxHeight && _autoResize == true){
 this.height = super.maxHeight;
 }
 else{
 if(_autoResize == true)    this.height = this.textField.measuredHeight+_lineOffset;

 }

 }
 else{
 if(_autoResize == true){
 this.height = this.textField.measuredHeight+_lineOffset;
 }

 }
 }
 }

 public function set autoResize(b:Boolean):void{
 _autoResize = b;
 doValidations();
 }

 }
}

Advertisements

[Pixel Bender] Bright Pass filter

I’m pretty sure you already heard about pixel bender, if not check Adobe’s  or Lee Brimelow’s website for awsome tutorials. 

Today I gonna share with you, my first pixel bender code ever, which is a bright pass filter. This filter set the dark pixels to black according a threshold value for the ‘darkness’.

kernel BrightPassFilter
< namespace : "com.gun.uieffect.filter"; vendor : "Guillaume Nachury. https://proofofconcepts.wordpress.com/"; version : 1; description : "Set all the dark pixels to black. The dark threshold value can be modified."; >
{
input image4 src;
output pixel4 dst;

parameter float thresholdValue;

void
evaluatePixel()
{
float Mx;
float mn;
float l;

pixel4 p;
p = sampleNearest(src,outCoord());

/*———————————————————————–
Here are some formulas to get the lightness :
———————————————————————–*/

/*(1) This one gave the best results so far.*/
l = (240.0/255.0)*(0.239*p.r+0.686*p.g+0.075*p.b);

/*(2) Quite the same as above but a bit tweaked
l = (240.0/255.0)*(0.300*p.r+0.590*p.g+0.110*p.b);
*/

/*(3) This one requires some steps before getting the lightness
//Find which component is the highest
if((p.r > p.g) && (p.r > p.b)){
Mx = p.r;
}
else if((p.g > p.r) && (p.g > p.b)){
Mx = p.g;
}
else if((p.b > p.g) && (p.b > p.r)){
Mx = p.b;
}

//Find which component is the lowest
if((p.r < p.g) && (p.r < p.b)){ mn = p.r; } else if((p.g < p.r) && (p.g < p.b)){ mn = p.g; } else if((p.b < p.g) && (p.b < p.r)){ mn = p.b; } l = 0.5*240.0*( (Mx+mn)/255.0), */ /*Formula I found, but not sure of the result l = (240.0/255.0)*Mx; */ if(l

NURVE – Public alpha release

I’m pretty excited today since I’m releasing the first public alpha version of a project I’m working on, based on Adobe AIR/FLEX and Papervision3D , called NURVE.

NURVE is 3D, film trailers browser with an iTunes coverflow like navigation experience. NURVE allows you to browse the newest films trailers and watch them in HD quality on any, internet connected, OS that have AIR installed

Preview:

 

As my first shot with both FLEX and Papervision3D and since NURVE is still under development you may find some bugs/glitches or suggestions so please drop me an email or leave a comment here.

=> Download NURVE  (don’t forget to install Adobe AIR  )

Expected in the new release:

  • more 3D animations
  • film information displayed
  • some fix 
  • new icons
  • more films source

 

Like most of my works, I will release le source code as soon as most of the bugs are fixed;)