Get Even or Odd – getParity using Action Script AS

Posted by druva | Flash, Flex, JS, as2, as3, utils | Thursday 4 February 2010 3:12 am

The below code shows how to use the class


import druva.NumberUtil;

trace('500', NumberUtil.getParity(500));
// true
trace('489', NumberUtil.getParity(489));
// false
trace('5', NumberUtil.getParity(5));
//false
trace('1', NumberUtil.getParity(1));
//true
trace('400', NumberUtil.getParity(400));
//false

This is the actual class


package druva {
  import flash.display.Sprite;

  public class NumberUtil extends Sprite{
    public function NumberUtil(){
    }

    public static function getParity(num:Number):String {
		return (num % 2) ? 'odd' : 'even';
	}

  }
}
 

perlinNoise using Flash ActionScript

Posted by druva | Flash, Flex, MXML, as3, utils | Friday 29 January 2010 2:47 pm

Simple Example to show how to use perlinNoise in Flash ActionScript

In the below example the stage is divided into two parts with two different effects

example

import flash.display.*;
import flash.events.Event;
import flash.geom.Point;

var _bitmap1:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight/2, true, 0xCCCCCC);
var _bitmap2:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight/2, true, 0xCCCCCC);

function perlinNoise() {
addChild(new Bitmap(_bitmap1));
_bitmap1.perlinNoise(10, 10, 2, 50, false, true,1, true);

var b:Bitmap = new Bitmap(_bitmap2);
b.y = stage.stageHeight/2;
addChild(b)
}

perlinNoise();

var t:Timer = new Timer(50)
t.addEventListener(TimerEvent.TIMER , onTimer);
var Size = 0;
var xPos = 0;
var yPos = 0;
function onTimer (e:TimerEvent) {
var point:Point=new Point(++xPos,++yPos);
_bitmap1.perlinNoise(10, 10, 2, 50, false, true,1, true, [point, point]);
++Size;
_bitmap2.perlinNoise(Size,Size, 2, 50, false, true,1, true, [point, point]);
if(Size > 50){
Size = 0;
}
}

t.start();

(more…)

 

Load Date from XML File using flash actionscript AS3

Posted by druva | Experiments, Flash, Flex, as3, utils | Wednesday 27 January 2010 1:42 pm

Simple Example to show how to load xml

package
{
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    public class DocumentClass extends Sprite
    {
        private var loader:URLLoader;
        private var xmlPath:URLRequest;

        public function DocumentClass()
        {
	 xmlPath = new URLRequest("http://server.com/xml.xml")
	loader = new URLLoader(xmlPath);
            loader.addEventListener(Event.COMPLETE, completeListener);
            loader.addEventListener(ProgressEvent.PROGRESS, progressListener);
        }

        private function completeListener(event:Event):void
        {
            trace(" all done loading " + loader.data + " and here's the xml file we loaded ");
        }

        private function progressListener(event:Event):void
        {
            trace(" loading.... " + loader.bytesLoaded + " / " + loader.bytesTotal + " bytes");
        }
    }
}
 

How to use URLVariables() in Flash AS3?

Posted by druva | Flash, Flex, as3, utils | Monday 25 January 2010 10:26 pm

Using URLVariables in Flash or Flex we can send and receive data from server he is the example

This is the PHP Code nested in the server
Create a PHP file and place it in the server

<?php
 $email=$_POST['email'];
 $password=$_POST['password'];

echo "email=".$_POST['email']."&amp;password=".$password;
?>

Here is the code in Flash/Flex

//create URLRequest instace withe the target URL
var request:URLRequest = new URLRequest("http://www.example.com/data.php");

//create instance of the class
var variables:URLVariables = new URLVariables();

variables.email = druva.flash@gmail.com;
variables.password = 'dontexpectit';

//add the data to the URLRequest
request.data = variables;

//Choose a method as POST
request.method = URLRequestMethod.POST;

var loader:URLLoader = new URLLoader();
//Create EventListener
loader.addEventListener(Event.COMPLETE, handleComplete);

//send the request with URLLoader()
loader.load(request);

 function handleComplete(event:Event)  {
var loader:URLLoader = URLLoader(event.target);
var vars:URLVariables = new URLVariables(loader.data);

//Read data for the result
trace("vars.email: "+vars.email);
trace("vars.password: "+vars.password);
 }
 

Create Color Wheel using Flex (Actionscript) AS3

Posted by druva | Flash, Flex, MXML, as3, utils | Sunday 24 January 2010 9:34 am

Working on color wheel i hope it looks good.
Cick to view working sample

 

Create Color Picker like Photoshop Color Picker using Flex and Actionscript 3 (AS3)

Posted by druva | Flash, Flex, MXML, as3, utils | Friday 15 January 2010 12:30 pm

Recently started making a color picker which is similar to photoshop color picker

 

Validate Email without RegExp in AS2 and AS3 in Flash

Posted by druva | Flash, Flex, as2, as3, utils | Tuesday 5 January 2010 12:22 am

The below code shows how to use the class


import druva.emailValidator;

trace('druva.flash@gmail.com &gt; '+emailValidator.isValid('druva.flash@gmail.com'));
// true
trace('druva.flash@gmail &gt; '+emailValidator.isValid('druva.flash@gmail'));
// false
trace('druva.@.com &gt; '+emailValidator.isValid('druva.@.com'));
//false
trace('druva.@gmail.com &gt; '+emailValidator.isValid('druva.@gmail.com'));
//true
trace('.aa@gmailcom &gt; '+emailValidator.isValid('.aa@gmailcom'));
//false

This is the actual class for validation


package druva {
  import flash.display.Sprite;

  public class emailValidator extends Sprite{
    public function emailValidator(){
    }

    public static function isValid(em:String):Boolean {

        var sEmail:String = new String(em);
        var validEmail:Boolean = true;
        var numDotPos:int = sEmail.indexOf(&quot;@&quot;);
        var nDotIndex:int = sEmail.lastIndexOf(&quot;.&quot;);
        if(numDotPos == -1 || nDotIndex == -1) {
          validEmail = false;
        }
        if(!(numDotPos &gt; 0)) {
          validEmail = false;
        }
          if(!(nDotIndex &gt; numDotPos)) {
        validEmail = false;
        }
        if(!(numDotPos &lt; sEmail.length - 1) || !(nDotIndex &gt; numDotPos + 1)) {
          validEmail = false;
        }
        return validEmail;
    }

  }
}
 

Create Rounded Corners Rectangle with Actionscript 3.0 – AS3

Posted by druva | Flash, Flex, as3, utils | Saturday 7 November 2009 8:14 am

Rounded Corner Rectangle

import flash.display.*;

function round_rectangle(){

var shape:Shape = new Shape();
addChild(shape);

shape.graphics.beginFill(0xFF0000FF, 1.0);

shape.graphics.drawRoundRect(50, 10, 200, 100, 30, 30);

shape.graphics.endFill();
}

round_rectangle();

(more…)

 

Open PoPup From Flash

Posted by druva | Flash, Flex, as3, utils | Friday 20 March 2009 1:21 pm
var b:Button = new Button();
b.label = 'openNewWindow';
addChild(b);
b.addEventListener(MouseEvent.MOUSE_DOWN, OpenPopUpWindow);
function OpenPopUpWindow(e:MouseEvent):void {
  var result:String = ;
  var url:URLRequest = new URLRequest("javascript:window.open('http://www.totusinfo.com','win','height=800,
           width=800,toolbar=yes,scrollbars=yes');void(0);");
  navigateToURL(url, "_self");
}
 

Remove White spaces from string in flash – Actionscript 3 (AS3)

Posted by druva | Flash, Flex, MXML, as3, utils | Monday 12 January 2009 4:06 am

This examples shows how to remove white spaces from the string


 public function removeSpaces(str:String):String {
 if (str == null) { return ''; }
 return str.replace(/\s+/g, '');
 }

This is the complete flex example


&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application
 xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
 layout=&quot;absolute&quot;&gt;
 &lt;mx:Script&gt;
 &lt;![CDATA[

 public function removeSpaces(str:String):String {
 if (str == null) { return ''; }
 return str.replace(/\s+/g, '');
 }
 public function on_trim_button():void {
 reultText.text = removeSpaces(originalText.text);
 }
 ]]&gt;
 &lt;/mx:Script&gt;
 &lt;mx:Button x=&quot;74&quot; y=&quot;101&quot; label=&quot;Trim Spaces&quot; click=&quot;on_trim_button()&quot;/&gt;
 &lt;mx:TextArea x=&quot;74&quot; y=&quot;42&quot; id=&quot;originalText&quot; /&gt;
 &lt;mx:TextArea x=&quot;74&quot; y=&quot;157&quot; id=&quot;reultText&quot; /&gt;
 &lt;mx:Label x=&quot;74&quot; y=&quot;16&quot; text=&quot;Enter Text&quot; width=&quot;160&quot;/&gt;
 &lt;mx:Label x=&quot;74&quot; y=&quot;131&quot; text=&quot;Enter Text&quot; width=&quot;160&quot;/&gt;
&lt;/mx:Application&gt;
 
Next Page »