Asv3's Blog

April 28, 2010

Simple Form Submit in AS3

Filed under: actionscript, as3, flash — asv3 @ 6:04 pm

Here is the code one of my friend asked, he wanted flash to submit some data on click of a button. This script assumes you have a Movieclip with instance name “but1” on stage.

but1.addEventListener("click",submitContact);

function submitContact(e:Event) {
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("email.php");
var varLoader:URLLoader = new URLLoader;
varSend.method = URLRequestMethod.GET;
varSend.data = variables;
variables.Name="Ravi";
variables.Email="Ravi@Some.com";
varLoader.load(varSend)
}

December 26, 2009

Offline Help on CS4

Filed under: flash — Tags: , , , , , , , — asv3 @ 11:40 pm

If you are new to Flash CS4, and you had habit of pressing F1 on info regarding selecting Class in action-script editor, you run in to this problem. every time you press ‘F1’ you see flash opens new browser window connecting to help.adobe.com. this is the URL opened when I pressed ‘F1’ after selecting MovieClip in code view. I thought flash removed offline help and cursed Adobe for the same. But finally I figured out I was wrong cursing Adobe. You should set your connection settings to offline mode to see offline help on your box.

  1. Select Window menu
  2. Select Extensions
  3. Select Connections
  4. click on right-top drop down to open offline options
  5. Select “Keep me offline” checkbox
  6. You are done.

Next time when you press ‘F1’ Flash CS4 opens offline help pages in new browser window.

November 12, 2009

PNG export problem with Flash CS4

Filed under: flash — Tags: , , , , , , , , , , , , , — asv3 @ 1:57 pm

If you are using Flash CS4 to draw transparent graphics and intend to use them in photoshop later, think twice there is a problem here. Some time Flash CS4 adds some black edges similar to matte edges in GIF, even if you select PNG 24-bit with Alpha Channel. This problem got introduced in Flash CS4, hope Adobe fix it soon. any way solution of this issue seems to be simple, but it’s a work around.

First break apart all text in your graphic, remember to break apart text completely you have to break apart twice. try exporting now, most of the cases this should solve your problems, if not then go ahead and break apart symbols in your graphic. exporting now will give to smooth edged PNG. But by breaking symbols to shapes will often you loose shape arrangements, things behind can come forward, or thing front can go backward. To avoid this situation before breaking apart select all elements in your graphics and “Distribute to Layers” Ctrl+Shift+D, should do that, by doing so every shape, element will get a layer for them selves, breaking apart now will not loose arrangements.

October 17, 2009

Filtering Array For Objects with Unique values in ActionScript

Filed under: actionscript, flash, flex — Tags: , , , , , , — asv3 @ 8:33 am

I happened to go through many instances where I had to filter a flat list on given attribute for unique values. For example I have flat list of employees who is working in different territory with there achievements, problem is show the graph based on territory. In flex you can use GroupedColletion to achieve this, but if you doing it in flash you are left with no options other than Array.filter. Here is how I did it.

var flatData:Array = [

{ Region:"Southwest", Territory:"Arizona", Territory_Rep:"Barbara Jennings", Estimate:40000 , Actual:38865 },

{ Region:"Southwest", Territory:"Arizona", Territory_Rep:"Dana Binn", Estimate:30000 , Actual:29885 },

{ Region:"Southwest", Territory:"Central California", Territory_Rep:"Joe Schmoe" , Estimate:30000 , Actual:29134 },

{ Region:"Southwest", Territory:"Northern California" , Territory_Rep:"Lauren Ipsum" , Estimate:40000 , Actual:38805 },

{ Region:"Southwest", Territory:"Northern California" , Territory_Rep:"T.R. Smith" , Estimate:40000 , Actual:55498 },

{ Region:"Southwest", Territory:"Southern California" , Territory_Rep:"Jane Grove" , Estimate:45000 , Actual:44913 },

{ Region:"Southwest", Territory:"Southern California" , Territory_Rep:"Alice Treu" , Estimate:45000 , Actual:44985 },

{ Region:"Southwest", Territory:"Nevada" , Territory_Rep:"Bethany Pittman", Estimate:45000 , Actual:52888 }

];

 

// sort first to make sure filter logic doesn’t fail

flatData.sortOn("Territory");

// function to return true for false for filtering

function is_unique_ter(item:*, index:int, arr:Array) {

    if (index<arr.length1) {

        return item.Territory!=arr[index+1].Territory;

    } else {

        return true;

    }

 

}

 

//assign filtered data to different array

var filteredflatData:Array=flatData.filter(is_unique_ter);

 

// trace out contents of filteredflatData

for (var i:Object in filteredflatData) {

    var s="";

    for (var j:String in filteredflatData[i]) {

        s+=( filteredflatData[i][j])+",";

    }

    trace(s);

}

it should give trace output like this:

30000,Southwest,Arizona,29885,Dana Binn,
30000,Southwest,Central California,29134,Joe Schmoe,
45000,Southwest,Nevada,52888,Bethany Pittman,
40000,Southwest,Northern California,55498,T.R. Smith,
45000,Southwest,Southern California,44913,Jane Grove,

September 26, 2009

Introduction to Flex

Filed under: flash, flex — Tags: , , , , — asv3 @ 10:43 pm

What is Flex?
Flex is the way to make Rich Internet Applications quickly and easily. It’s a framework for creating RIAs that run with widely deployed Flash Player. At its heart it uses two languages namely MXML, a markup language based on Extensive Markup Language (XML) and ActionScript an EMCAScript based native scripting language of Flash platform.

Why Flex?
Quick, Easy, Well Supported: Flex gives you interactivity in a robust development environment. The Flash Platform gives you more reach and more tools than any other technology out there. It really is the next generation of web applications and Flex has made it easy to jump in and take advantage.

Flex is nothing but Flash: Just like Flash movies Flex is deployed as SWF files to be played in Flash run-time environments like Flash Player in browser, Adobe Integrated Runtime (AIR) and Flash Lite (mobile Flash player).

September 15, 2009

Flash Training

Filed under: flash — Tags: , , , , — asv3 @ 12:01 pm

Recently I did a flash training at my office,  there were 10 attendants, but I guess that’s not bad for beginner. here is the presentation I used for the training.

Intro to AS3 using Flash CS3

September 13, 2009

Flash Document

Filed under: flash — Tags: , , , — asv3 @ 8:43 pm

When we create a new file in Flash IDE, we save it in “.fla” document. We call this fla document as a Flash Document.

Every flash document got it’s  own time-line, Stage of given width and height.

We can think of a flash document like a real-world stage play. Both got stages, here actors are symbols. we can add, remove, change, modify actors through out the time line. Every Symbol has it’s own behavior, but we can customize and change as per the requirements.

By default document time line got one layer, we can add or remove layer as per the requirement. We add symbols to layers. Flash time line can contain 2 kinds of frames, Keyframes and Regular Frames.

Key frame: is a frame whose on-Stage content differs from the preceding frame.

Regular frame: by contrast, is a frame that’s on-Stage content is automatically carried over (repeated) from the preceding closest keyframe

Symbols and Instances

Flash support three types of symbols.

• Movie Clip (for animations with programmatic content)
• Graphic (for nonprogrammatic animations that can be previewed directly in the Flash authoring tool)
• Button (for simple interactivity)

When we create a symbol master copy of that symbol is stored in library. Whatever we see on the stage is instance of those symbols, aka related copies of that symbol. changing symbol affect all instances, but change instance doesn’t affect symbol.

Accessing child clips of a movie

getChildAt()
getChildByName()

Timeline Control

  • play( )
  • stop( )
  • gotoAndPlay( )
  • gotoAndStop( )
  • nextFrame( )
  • prevFrame( )
  • currentFrame
  • currentLabel
  • currentLabels
  • totalFrames

Drawing API

Filed under: flash — Tags: , , , , , — asv3 @ 7:29 pm

ActionScript allows us  to create primitive vector shapes and lines via Graphics class. Each ActionScript class that supports drawing creates an instance of Graphics class through which we care add graphical elements into it.

Say for example you have a class by name Ball.

you create a new instance of ball like

var smallBall:Ball = new Ball()

assuming that Ball is of width and height equal to 100px, to draw a border around the ball you can you code like this.

smallBall.graphics.lineStyle(1, 0x000000);
smallBall.graphics.moveTo(0, 0);
smallBall.graphics.lineTo(100, 0);
smallBall.graphics.lineTo(100, 100);
smallBall.graphics.lineTo(0, 100);
smallBall.graphics.lineTo(0, 0);

you can categorize methods of Graphics class as follows:

Drawing lines
curveTo( ), lineTo( )

Drawing shapes
beginBitmapFill( ), beginFill( ), beginGradientFill( ),  drawCircle( ), drawEllipse( ), drawRect( ), drawRoundRect( ),
drawRoundRectComplex( ), endFill( )

Defining line styles
lineGradientStyle( ), lineStyle( )
Moving the drawing pen
moveTo( )

Removing graphics
clear( )

Timer Event

Filed under: flash — Tags: , , , , — asv3 @ 4:01 pm

Timer Events are events that  get triggered between given delay (in milliseconds).

Using Timer Events in Actionscript

var timer:Timer = new Timer( );

timer.delay = 100;

timer.repeatCount = 5;

timer.repeatCount = 0; // Unlimited TimerEvent.TIMER events

function timerListener (e:TimerEvent):void {
// Code here will execute when triggered by a TimerEvent.TIMER event
}

timer.addEventListener(TimerEvent.TIMER, timerListener);

timer.start()

and use timer.stop() to stop timer event triggering.

Enterframe Events

Filed under: flash, Uncategorized — Tags: , , — asv3 @ 12:42 pm

EnterFrame is an event that get dispatched according to the frame rate of given movie. we can assign frame rate for a flash movie between 12 to 120.

Say if we associate an Enterframe event listener to Stage of a movie which has frame rate 20, flash run time tries to dispatch 20 Enterframe events per second. This is basically used to animate graphical objects in flash, but we cannot completely assume that this event will get triggered with respect to the given frame rate.

the Flash runtime does not always achieve the designated frame rate. If the computer is too slow to render frames fast enough to keep up with the designated frame rate, the animation slows down. This slowdown can even vary depending on the system load; if other programs are running or if Flash is performing some processor-intensive task, the frame rate may drop for only a short period and then resume its normal pace.

Older Posts »

Create a free website or blog at WordPress.com.