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

CS4 set brightness contrast hue saturation with actionscript

Posted by druva | Uncategorized | Sunday 12 July 2009 12:05 pm

This logic also works for flex


package  {
     import flash.filters.ColorMatrixFilter;
     import flash.display.MovieClip;
     import flash.display.Loader;
	 import fl.controls.Slider;
     import flash.net.URLRequest;
     import fl.motion.*;
     import flash.events.Event;  

     public class AdjustColorExample extends MovieClip
     {
	 	 private var loader:Loader = new Loader();
		 private var Br_slider:Slider;
		 private var co_slider:Slider;
		 private var hu_slider:Slider;
		 private var sa_slider:Slider;
         public function AdjustColorExample() {
             var imgUrl:String = "http://www.helpexamples.com/flash/images/image1.jpg";
             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, setFilter);
             var request:URLRequest = new URLRequest(imgUrl);
             loader.load(request);
             addChild(loader);
			 //-- min -100 and max 100 for  brightness
			 Br_slider = getSlider(-100, 100, 50, 390, 300);
			 //-- min -100 and max 100 for  contrast
		     co_slider = getSlider(-100, 100, 50, 420, 300);
			 //-- min -180 and max 180 for  hue
		     hu_slider = getSlider(-180, 180, 50, 450, 300);
			 //-- min -100 and max 100 for  saturation
		     sa_slider = getSlider(-100, 100, 50, 480, 300);

         }
		 private function getSlider(min, max, xx, yy, w){
		 	var slider:Slider = new Slider();
			    slider.minimum  = min;
			    slider.maximum  = max;
			    slider.x  = xx;
			    slider.y  = yy;
			    slider.width  = w;
				slider.addEventListener(Event.CHANGE, onChange);
				addChild(slider);
				return slider;
		 }

        public function onChange(e:Event):void {
			setFilter(e)
        }  

		private function setFilter(e:Event){
             var myColor:AdjustColor = new AdjustColor();
             myColor.brightness = Br_slider.value;
             myColor.contrast = co_slider.value;
             myColor.hue = hu_slider.value;
             myColor.saturation = sa_slider.value;
             var matrix:Array = new Array();
             matrix = myColor.CalculateFinalFlatArray();
             var filter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
             var myFilters:Array = new Array();
             myFilters.push(filter);
             loader.filters = myFilters;
		}
     }
}

This movie requires Flash Player 9

 

Open URL in another window using flash actionscript

Posted by Vineela | Flash, as3, utils | Friday 28 November 2008 9:59 am

import flash.display.*;

buttonLabel.addEventListener(MouseEvent.CLICK, button_click);

function button_click(evt:MouseEvent):void {
    var reqURL:URLRequest = new URLRequest("http://www.totusinfo.com/");
	navigateToURL(reqURL, "_self");
}
 

HTML Java Script POPUP from Action Script

Posted by druva | Flash, Flex, as3, utils | Saturday 1 November 2008 2:26 am

This examples shows how open HTML Java Script POPUP from Action Script


button.addEventListener(MouseEvent.MOUSE_DOWN, onClick);

function onClick(e:MouseEvent):void {
 var jscommand:String = "window.open('http://www.google.com','win', 'width=300,height=400,toolbar=no,scrollbars=yes');";
 var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
 navigateToURL(url, "_self");
}