SlideShare ist ein Scribd-Unternehmen logo
1 von 78
Custom Formatter,  Validator,  and Effect Components ,[object Object]
About Me ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Scenarios ,[object Object],[object Object],[object Object]
Scenario #1 ,[object Object],[object Object]
Formatters ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example of Number Formatter ,[object Object]
NumberFormatter import  mx.formatters.NumberFormatter; private   var  myString:String =  "1234567" ; private   function  format():String{ var  numFormatter:NumberFormatter =  new  NumberFormatter(); return  numFormatter.format(myString); } Demo
Example of Number Formatter ,[object Object],[object Object]
Possible Solutions ,[object Object],private   var  myString:String =  "1234567" ; private   function  format():String{ var  sub1:String = myString.substr(0,2); var  sub2:String = myString.substr(2,5); return  sub1 +  "-"  + sub2; } Demo
Feeling Proud ,[object Object],[object Object]
Scope Creep  ,[object Object],[object Object],[object Object]
Solutions ,[object Object]
Solutions ,[object Object],[object Object]
How Many? ,[object Object]
What is it? ,[object Object]
What is it? ,[object Object]
Custom Format String import  mx.formatters.SwitchSymbolFormatter; private   var  myString:String =  "1234567" ; private   function  format():String{ var  ssFormatter:SwitchSymbolFormatter =  new   SwitchSymbolFormatter(); return  ssFormatter.formatValue( "##-###-##" ,myString); } Demo
Scope Creep #2 ,[object Object]
Solution? ,[object Object]
Solution? ,[object Object],[object Object]
Solution? ,[object Object],[object Object],[object Object],[object Object]
Solution That will work ,[object Object]
Solution That will work ,[object Object],[object Object]
Custom Format Characters import  mx.formatters.SwitchSymbolFormatter; private   var  myString:String =  "1234567" ; private   function  format():String{ var  ssFormatter:SwitchSymbolFormatter =  new  SwitchSymbolFormatter( "*" ); return  ssFormatter.formatValue( "#**-**-***" ,myString); } Demo
Scenario #2 ,[object Object],[object Object]
Solution ,[object Object],private   function  format(s:String):String{ var  returnString:String =  "" ; // loop through value and build string in reverse for ( var  i:Number=s.length; i>=0; i--){ returnString = returnString + s.charAt(i); } return  returnString; }
Solution ,[object Object]
Solution ,[object Object],[object Object]
How? ,[object Object]
How? ,[object Object],[object Object]
ReverseFormatter class package  com.everythingflex.flex.formatters { import  mx.formatters.Formatter // Custom formatters must extend mx.formatters.Formatter public   class  ReverseFormatter  extends  Formatter { public   function  ReverseFormatter() { super (); } // Custom formatters must override format(). override   public   function  format(formatObj:Object):String{ // ADD OVERRIDE HERE } } }
ReverseFormatter override format method // Custom formatters must override format(). override   public   function  format(formatObj:Object):String{ if (formatObj.length == 0) {  // return empty string and set error property if string  //has zero length. error= "Can not format an empty String" ; return   "" }  else  { error= null ; var  returnString:String =  "" ; // loop through value and build string in reverse for ( var  i:Number=formatObj.length; i>=0; i--){ returnString = returnString + formatObj.charAt(i); } return  returnString; }
Using ReverseFormatter import  ReverseFormatter; private   var  myString:String =  "Rich Tretola" ; private   function  format():String{ var  reverseFormatter:ReverseFormatter =  new  ReverseFormatter(); return  reverseFormatter.format(myString); } Demo
Scenario #3 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Solutions ,[object Object]
Solutions ,[object Object],[object Object]
Custom Validator ,[object Object],[object Object],[object Object]
PasswordValidator class package  com.everythingflex.flex.validators  { import  mx.validators.Validator; import  mx.validators.ValidationResult; public   class  PasswordValidator  extends  Validator { private   var  results:Array; public   function  PasswordValidator() { super (); } // Override the doValidation() method. override   protected   function  doValidation(value:Object):Array { // ADD OVERRIDE HERE } } }
Override doValidation // Override the doValidation() method. override   protected   function  doValidation(value:Object):Array { results = []; // Call super's doValidation(). results =  super .doValidation(value);  // Return if super's doValidation contains // errors (required would be an example). if  (results.length > 0){ return  results; } // *****Add Custom Validation Here***** return  results; }
Now add custom validation // Check for min length if  (dataString.length < 6){ results.push( new  ValidationResult( true ,  null ,  &quot;Short&quot; ,  &quot;Password must be at least 6 characters.&quot; )); return  results; }  var  dataString:String = String(value); // Check for max length (this can be set in the text component's maxChars property). if  (dataString.length > 10){ results.push( new  ValidationResult( true ,  null ,  &quot;Long&quot; ,  &quot;Password must be no larger than 10 characters.&quot; )); return  results; }
More custom validation // Check for at least 1 upper case letter. if  (dataString.search( &quot;[A-Z]&quot; )<0) { results.push( new  ValidationResult( true ,  null ,  &quot;Upper&quot; ,  &quot;Passwords must contain at least one upper case letter.&quot; )); return  results; } // Check for at least 1 lower case letter. if  (dataString.search( &quot;[a-z]&quot; )<0) { results.push( new  ValidationResult( true ,  null ,  &quot;Lower&quot; ,  &quot;Passwords must contain at lease one lower case letter.&quot; )); return  results; } // Check for at least 1 number. if  (dataString.search( &quot;[0-9]&quot; )<0) { results.push( new  ValidationResult( true ,  null ,  &quot;Number&quot; ,  &quot;Passwords must contain at least one number.&quot; )); return  results; }
Results Demo
Scenario #4 ,[object Object]
Solution ,[object Object],private   function  rollOver(event:MouseEvent): void { event.target.scaleX=2; event.target.scaleY=2; } private   function  rollOut(event:MouseEvent): void { event.target.scaleX=1; event.target.scaleY=1; } <mx:Button  mouseOver=&quot;rollOver(event)&quot;  mouseOut=&quot;rollOut(event)&quot;  />
Solution ,[object Object]
Solution ,[object Object],[object Object]
Creating a Custom Effect ,[object Object],[object Object],[object Object]
Effect Class ,[object Object],[object Object],[object Object],[object Object]
ScaleEffect Class package  com.everythingflex.flex.effects { import  mx.effects.Effect; import  mx.effects.EffectInstance; import  mx.effects.IEffectInstance; public   class  ScaleEffect  extends  Effect { // Define scaleTo parameter public   var  scaleTo:Number; public   function  ScaleEffect(targetObj:Object =  null ){ super (targetObj); instanceClass= ScaleEffectInstance;  } // ADD Override getAffectedProperties() // ADD Override initInstance()   } }
ScaleEffect Overrides // override getAffectedProperties() and  // pass the properties effected  override   public   function  getAffectedProperties():Array{ return  [ &quot;scaleX,scaleY&quot; ]; } // Override initInstance() override   protected   function  initInstance(inst:IEffectInstance): void { super .initInstance(inst); ScaleEffectInstance(inst).scaleTo = scaleTo;  }
EffectInstance Class ,[object Object],[object Object]
ScaleEffectInstance Class package  com.everythingflex.flex.effects { import  mx.effects.EffectInstance; public   class  ScaleEffectInstance  extends  EffectInstance { // Custom Parameter public   var  scaleTo:Number; public   function  ScaleEffectInstance(targetObj:Object) { super (targetObj); } // ADD Override play() method. // ADD Override reverse() method. } }
ScaleEffectInstance Overrides // Override play() method. override   public   function  play(): void { super .play(); target.scaleX=scaleTo; target.scaleY=scaleTo; } // Override reverse() method. override   public   function  reverse(): void { target.scaleX=1; target.scaleY=1; }
Results Demo
Scenario #5 ,[object Object],[object Object]
Solution ,[object Object],[object Object]
Custom TweenEffect ,[object Object],[object Object],[object Object]
TweenEffect class ,[object Object],[object Object],[object Object],[object Object]
MoveBounceTweenEffect Class package  com.everythingflex.flex.effects { import  mx.effects.TweenEffect; import  mx.effects.EffectInstance; import  mx.effects.IEffectInstance; public   class  MoveBounceTweenEffect  extends  TweenEffect{ // Define xFrom and xTo parameters public   var  xFrom:Number; public   var  xTo:Number; public   function  MoveBounceTweenEffect(targetObj:Object =  null ){ super (targetObj); instanceClass= MoveBounceTweenEffectInstance;  } // ADD Override getAffectedProperties() // ADD Override initInstance()   }
MoveBounceTweenEffect Overrides // override getAffectedProperties() and  // pass the properties effected  override   public   function  getAffectedProperties():Array{ return  [ &quot;x&quot; ]; } // Override initInstance() override   protected   function  initInstance(inst:IEffectInstance): void { super .initInstance(inst); MoveBounceTweenEffectInstance(inst).xFrom = xFrom; MoveBounceTweenEffectInstance(inst).xTo = xTo; }
TweenEffectInstance ,[object Object],[object Object],[object Object],[object Object]
MoveBounceTweenEffectInstance package { import  mx.effects.effectClasses.TweenEffectInstance; import  mx.effects.Tween; public   class  MoveBounceTweenEffectInstance  extends  TweenEffectInstance { // Move parameters public   var  xFrom:Number; public   var  xTo:Number; public   function  MoveBounceTweenEffectInstance(targetObj:Object){ super (targetObj); } // Override play() method. override   public   function  play(): void { super .play(); // Create the Tween object var  tween:Tween = createTween( this , xFrom, xTo, duration);  } // Override onTweenUpdate() method. override   public   function  onTweenUpdate(val:Object): void { target.x = val; } // Override onTweenEnd() method. override   public   function  onTweenEnd(val:Object): void { // call super.onTweenEnd(). super .onTweenEnd(val); } } }
Results Demo
Forgot Something ,[object Object]
Forgot Something ,[object Object],[object Object]
Easing Function Easing function was borrowed from the Adobe docs private   function  bounceFunction(t:Number, b:Number, c:Number, d:Number):Number { if  ((t /= d) < (1 / 2.75)) { return  c * (7.5625 * t * t) + b; }  else   if  (t < (2 / 2.75)) { return  c * (7.5625 * (t-=(1.5/2.75)) * t + .75) + b; }  else   if  (t < (2.5 / 2.75)) { return  c * (7.5625 * (t-=(2.25/2.75)) * t + .9375) + b; }  else  { return  c * (7.5625 * (t-=(2.625/2.75)) * t + .984375) + b; } } MoveBounceTweenEffectInstance(inst).easingFunction = bounceFunction; Add it to the initInstance method
Results Demo
Benefits of Custom Effect ,[object Object],Demo
Wrap Up Hopefully, if I have done my job correctly you will now see the benefits of using custom classes for formatters, validators, and effects.
Prizes Question #1 ,[object Object]
Prizes Question #1 ,[object Object],[object Object]
Prizes Question #2 ,[object Object]
Prizes Question #2 ,[object Object],[object Object]
Prizes Question #3 ,[object Object]
Prizes Question #3 ,[object Object],[object Object]
Prizes Question #4 ,[object Object]
Prizes Question #4 ,[object Object],[object Object]
Contact and Downloads Rich Tretola [email_address]   or  [email_address] Pre sentation and Sour ce available at: http://blog.everythingflex.com

Weitere ähnliche Inhalte

Was ist angesagt?

Functional Effects - Part 1
Functional Effects - Part 1Functional Effects - Part 1
Functional Effects - Part 1Philip Schwarz
 
iOS best practices
iOS best practicesiOS best practices
iOS best practicesMaxim Vialyx
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象勇浩 赖
 
Activity diagram tutorial
Activity diagram tutorialActivity diagram tutorial
Activity diagram tutorialDeclan Chellar
 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascriptguest4d57e6
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NETDoommaker
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functionsmussawir20
 
non-strict functions, bottom and scala by-name parameters
non-strict functions, bottom and scala by-name parametersnon-strict functions, bottom and scala by-name parameters
non-strict functions, bottom and scala by-name parametersPhilip Schwarz
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6rohassanie
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3rohassanie
 
Java script – basic auroskills (2)
Java script – basic   auroskills (2)Java script – basic   auroskills (2)
Java script – basic auroskills (2)BoneyGawande
 
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsPython Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsP3 InfoTech Solutions Pvt. Ltd.
 
Let's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APILet's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APIMario Fusco
 

Was ist angesagt? (20)

Clean code
Clean codeClean code
Clean code
 
Functional Effects - Part 1
Functional Effects - Part 1Functional Effects - Part 1
Functional Effects - Part 1
 
iOS best practices
iOS best practicesiOS best practices
iOS best practices
 
Dsl
DslDsl
Dsl
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象
 
Activity diagram tutorial
Activity diagram tutorialActivity diagram tutorial
Activity diagram tutorial
 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascript
 
Python Programming Essentials - M17 - Functions
Python Programming Essentials - M17 - FunctionsPython Programming Essentials - M17 - Functions
Python Programming Essentials - M17 - Functions
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NET
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
non-strict functions, bottom and scala by-name parameters
non-strict functions, bottom and scala by-name parametersnon-strict functions, bottom and scala by-name parameters
non-strict functions, bottom and scala by-name parameters
 
09. Methods
09. Methods09. Methods
09. Methods
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
 
Vbscript
VbscriptVbscript
Vbscript
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
Java script – basic auroskills (2)
Java script – basic   auroskills (2)Java script – basic   auroskills (2)
Java script – basic auroskills (2)
 
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsPython Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and Loops
 
Let's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APILet's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java API
 
SQL -PHP Tutorial
SQL -PHP TutorialSQL -PHP Tutorial
SQL -PHP Tutorial
 

Andere mochten auch

360 Flex Atlanta
360 Flex Atlanta360 Flex Atlanta
360 Flex Atlantartretola
 
MAX 2007 - Flex to AIR
MAX 2007 - Flex to AIRMAX 2007 - Flex to AIR
MAX 2007 - Flex to AIRrtretola
 
New Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP ConnectorsNew Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP Connectorsrtretola
 
MAX 2008 - Building your 1st AIR application
MAX 2008 - Building your 1st AIR applicationMAX 2008 - Building your 1st AIR application
MAX 2008 - Building your 1st AIR applicationrtretola
 
Flash SEO Secrets
Flash SEO SecretsFlash SEO Secrets
Flash SEO Secretsrtretola
 
Must Have Apps for Windows 10
Must Have Apps for Windows 10Must Have Apps for Windows 10
Must Have Apps for Windows 10Wiley
 
Rethinking Website Design: Creating a Peak-Performing Website with Less Risk ...
Rethinking Website Design: Creating a Peak-Performing Website with Less Risk ...Rethinking Website Design: Creating a Peak-Performing Website with Less Risk ...
Rethinking Website Design: Creating a Peak-Performing Website with Less Risk ...HubSpot
 

Andere mochten auch (8)

360 Flex Atlanta
360 Flex Atlanta360 Flex Atlanta
360 Flex Atlanta
 
MAX 2007 - Flex to AIR
MAX 2007 - Flex to AIRMAX 2007 - Flex to AIR
MAX 2007 - Flex to AIR
 
New Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP ConnectorsNew Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP Connectors
 
MAX 2008 - Building your 1st AIR application
MAX 2008 - Building your 1st AIR applicationMAX 2008 - Building your 1st AIR application
MAX 2008 - Building your 1st AIR application
 
Flash SEO Secrets
Flash SEO SecretsFlash SEO Secrets
Flash SEO Secrets
 
[INFOGRAPHIC] 2015 State of Social Business
[INFOGRAPHIC] 2015 State of Social Business[INFOGRAPHIC] 2015 State of Social Business
[INFOGRAPHIC] 2015 State of Social Business
 
Must Have Apps for Windows 10
Must Have Apps for Windows 10Must Have Apps for Windows 10
Must Have Apps for Windows 10
 
Rethinking Website Design: Creating a Peak-Performing Website with Less Risk ...
Rethinking Website Design: Creating a Peak-Performing Website with Less Risk ...Rethinking Website Design: Creating a Peak-Performing Website with Less Risk ...
Rethinking Website Design: Creating a Peak-Performing Website with Less Risk ...
 

Ähnlich wie Custom Formatter, Validator, and Effect Components

Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java DevelopersYakov Fain
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]srikanthbkm
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003R696
 
Need help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdf
Need help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdfNeed help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdf
Need help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdffastechsrv
 
functions modules and exceptions handlings.ppt
functions modules and exceptions handlings.pptfunctions modules and exceptions handlings.ppt
functions modules and exceptions handlings.pptRajasekhar364622
 
Python programming variables and comment
Python programming variables and commentPython programming variables and comment
Python programming variables and commentMalligaarjunanN
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoftch samaram
 
QTP VB Script Trainings
QTP VB Script TrainingsQTP VB Script Trainings
QTP VB Script TrainingsAli Imran
 
Java script basics
Java script basicsJava script basics
Java script basicsJohn Smith
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiRan Mizrahi
 
Python programming - Functions and list and tuples
Python programming - Functions and list and tuplesPython programming - Functions and list and tuples
Python programming - Functions and list and tuplesMalligaarjunanN
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handlingSuite Solutions
 
Checking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioChecking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioPVS-Studio
 
Presentation - Course about JavaFX
Presentation - Course about JavaFXPresentation - Course about JavaFX
Presentation - Course about JavaFXTom Mix Petreca
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)James Titcumb
 

Ähnlich wie Custom Formatter, Validator, and Effect Components (20)

Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
 
Need help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdf
Need help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdfNeed help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdf
Need help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdf
 
functions modules and exceptions handlings.ppt
functions modules and exceptions handlings.pptfunctions modules and exceptions handlings.ppt
functions modules and exceptions handlings.ppt
 
Python programming variables and comment
Python programming variables and commentPython programming variables and comment
Python programming variables and comment
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoft
 
QTP VB Script Trainings
QTP VB Script TrainingsQTP VB Script Trainings
QTP VB Script Trainings
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Javascripting.pptx
Javascripting.pptxJavascripting.pptx
Javascripting.pptx
 
Clean code
Clean codeClean code
Clean code
 
Web programming
Web programmingWeb programming
Web programming
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
 
Python programming - Functions and list and tuples
Python programming - Functions and list and tuplesPython programming - Functions and list and tuples
Python programming - Functions and list and tuples
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
 
Checking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioChecking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-Studio
 
Presentation - Course about JavaFX
Presentation - Course about JavaFXPresentation - Course about JavaFX
Presentation - Course about JavaFX
 
Preprocessors
PreprocessorsPreprocessors
Preprocessors
 
Java 17
Java 17Java 17
Java 17
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
 

Kürzlich hochgeladen

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Kürzlich hochgeladen (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

Custom Formatter, Validator, and Effect Components

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. NumberFormatter import mx.formatters.NumberFormatter; private var myString:String = &quot;1234567&quot; ; private function format():String{ var numFormatter:NumberFormatter = new NumberFormatter(); return numFormatter.format(myString); } Demo
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. Custom Format String import mx.formatters.SwitchSymbolFormatter; private var myString:String = &quot;1234567&quot; ; private function format():String{ var ssFormatter:SwitchSymbolFormatter = new SwitchSymbolFormatter(); return ssFormatter.formatValue( &quot;##-###-##&quot; ,myString); } Demo
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. Custom Format Characters import mx.formatters.SwitchSymbolFormatter; private var myString:String = &quot;1234567&quot; ; private function format():String{ var ssFormatter:SwitchSymbolFormatter = new SwitchSymbolFormatter( &quot;*&quot; ); return ssFormatter.formatValue( &quot;#**-**-***&quot; ,myString); } Demo
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31. ReverseFormatter class package com.everythingflex.flex.formatters { import mx.formatters.Formatter // Custom formatters must extend mx.formatters.Formatter public class ReverseFormatter extends Formatter { public function ReverseFormatter() { super (); } // Custom formatters must override format(). override public function format(formatObj:Object):String{ // ADD OVERRIDE HERE } } }
  • 32. ReverseFormatter override format method // Custom formatters must override format(). override public function format(formatObj:Object):String{ if (formatObj.length == 0) { // return empty string and set error property if string //has zero length. error= &quot;Can not format an empty String&quot; ; return &quot;&quot; } else { error= null ; var returnString:String = &quot;&quot; ; // loop through value and build string in reverse for ( var i:Number=formatObj.length; i>=0; i--){ returnString = returnString + formatObj.charAt(i); } return returnString; }
  • 33. Using ReverseFormatter import ReverseFormatter; private var myString:String = &quot;Rich Tretola&quot; ; private function format():String{ var reverseFormatter:ReverseFormatter = new ReverseFormatter(); return reverseFormatter.format(myString); } Demo
  • 34.
  • 35.
  • 36.
  • 37.
  • 38. PasswordValidator class package com.everythingflex.flex.validators { import mx.validators.Validator; import mx.validators.ValidationResult; public class PasswordValidator extends Validator { private var results:Array; public function PasswordValidator() { super (); } // Override the doValidation() method. override protected function doValidation(value:Object):Array { // ADD OVERRIDE HERE } } }
  • 39. Override doValidation // Override the doValidation() method. override protected function doValidation(value:Object):Array { results = []; // Call super's doValidation(). results = super .doValidation(value); // Return if super's doValidation contains // errors (required would be an example). if (results.length > 0){ return results; } // *****Add Custom Validation Here***** return results; }
  • 40. Now add custom validation // Check for min length if (dataString.length < 6){ results.push( new ValidationResult( true , null , &quot;Short&quot; , &quot;Password must be at least 6 characters.&quot; )); return results; } var dataString:String = String(value); // Check for max length (this can be set in the text component's maxChars property). if (dataString.length > 10){ results.push( new ValidationResult( true , null , &quot;Long&quot; , &quot;Password must be no larger than 10 characters.&quot; )); return results; }
  • 41. More custom validation // Check for at least 1 upper case letter. if (dataString.search( &quot;[A-Z]&quot; )<0) { results.push( new ValidationResult( true , null , &quot;Upper&quot; , &quot;Passwords must contain at least one upper case letter.&quot; )); return results; } // Check for at least 1 lower case letter. if (dataString.search( &quot;[a-z]&quot; )<0) { results.push( new ValidationResult( true , null , &quot;Lower&quot; , &quot;Passwords must contain at lease one lower case letter.&quot; )); return results; } // Check for at least 1 number. if (dataString.search( &quot;[0-9]&quot; )<0) { results.push( new ValidationResult( true , null , &quot;Number&quot; , &quot;Passwords must contain at least one number.&quot; )); return results; }
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49. ScaleEffect Class package com.everythingflex.flex.effects { import mx.effects.Effect; import mx.effects.EffectInstance; import mx.effects.IEffectInstance; public class ScaleEffect extends Effect { // Define scaleTo parameter public var scaleTo:Number; public function ScaleEffect(targetObj:Object = null ){ super (targetObj); instanceClass= ScaleEffectInstance; } // ADD Override getAffectedProperties() // ADD Override initInstance() } }
  • 50. ScaleEffect Overrides // override getAffectedProperties() and // pass the properties effected override public function getAffectedProperties():Array{ return [ &quot;scaleX,scaleY&quot; ]; } // Override initInstance() override protected function initInstance(inst:IEffectInstance): void { super .initInstance(inst); ScaleEffectInstance(inst).scaleTo = scaleTo; }
  • 51.
  • 52. ScaleEffectInstance Class package com.everythingflex.flex.effects { import mx.effects.EffectInstance; public class ScaleEffectInstance extends EffectInstance { // Custom Parameter public var scaleTo:Number; public function ScaleEffectInstance(targetObj:Object) { super (targetObj); } // ADD Override play() method. // ADD Override reverse() method. } }
  • 53. ScaleEffectInstance Overrides // Override play() method. override public function play(): void { super .play(); target.scaleX=scaleTo; target.scaleY=scaleTo; } // Override reverse() method. override public function reverse(): void { target.scaleX=1; target.scaleY=1; }
  • 55.
  • 56.
  • 57.
  • 58.
  • 59. MoveBounceTweenEffect Class package com.everythingflex.flex.effects { import mx.effects.TweenEffect; import mx.effects.EffectInstance; import mx.effects.IEffectInstance; public class MoveBounceTweenEffect extends TweenEffect{ // Define xFrom and xTo parameters public var xFrom:Number; public var xTo:Number; public function MoveBounceTweenEffect(targetObj:Object = null ){ super (targetObj); instanceClass= MoveBounceTweenEffectInstance; } // ADD Override getAffectedProperties() // ADD Override initInstance() }
  • 60. MoveBounceTweenEffect Overrides // override getAffectedProperties() and // pass the properties effected override public function getAffectedProperties():Array{ return [ &quot;x&quot; ]; } // Override initInstance() override protected function initInstance(inst:IEffectInstance): void { super .initInstance(inst); MoveBounceTweenEffectInstance(inst).xFrom = xFrom; MoveBounceTweenEffectInstance(inst).xTo = xTo; }
  • 61.
  • 62. MoveBounceTweenEffectInstance package { import mx.effects.effectClasses.TweenEffectInstance; import mx.effects.Tween; public class MoveBounceTweenEffectInstance extends TweenEffectInstance { // Move parameters public var xFrom:Number; public var xTo:Number; public function MoveBounceTweenEffectInstance(targetObj:Object){ super (targetObj); } // Override play() method. override public function play(): void { super .play(); // Create the Tween object var tween:Tween = createTween( this , xFrom, xTo, duration); } // Override onTweenUpdate() method. override public function onTweenUpdate(val:Object): void { target.x = val; } // Override onTweenEnd() method. override public function onTweenEnd(val:Object): void { // call super.onTweenEnd(). super .onTweenEnd(val); } } }
  • 64.
  • 65.
  • 66. Easing Function Easing function was borrowed from the Adobe docs private function bounceFunction(t:Number, b:Number, c:Number, d:Number):Number { if ((t /= d) < (1 / 2.75)) { return c * (7.5625 * t * t) + b; } else if (t < (2 / 2.75)) { return c * (7.5625 * (t-=(1.5/2.75)) * t + .75) + b; } else if (t < (2.5 / 2.75)) { return c * (7.5625 * (t-=(2.25/2.75)) * t + .9375) + b; } else { return c * (7.5625 * (t-=(2.625/2.75)) * t + .984375) + b; } } MoveBounceTweenEffectInstance(inst).easingFunction = bounceFunction; Add it to the initInstance method
  • 68.
  • 69. Wrap Up Hopefully, if I have done my job correctly you will now see the benefits of using custom classes for formatters, validators, and effects.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78. Contact and Downloads Rich Tretola [email_address] or [email_address] Pre sentation and Sour ce available at: http://blog.everythingflex.com