Flash AS3 - Tutorials and Articles

Get current URL or Domain of current flash location

Get current URL or Domain of current flash location

ExternalInterface for Domain Name

/* -------- ExternalInterface for Domain Name ------- */
import flash.external.*;
var urlPath;
function geturlhttp() {
urlPath = ExternalInterface.call("window.location.href.toString");
}
geturlhttp();
trace(urlPath);

LocalConnection for Domain Name

/* -------- LocalConnection for Domain Name ------- */
import flash.net.LocalConnection;
var lc:LocalConnection = new LocalConnection();
var domain:String = lc.domain;
trace(domain);

Tweening color using AS3 Tweener Class

// import as3 tweener
import caurina.transitions.*;

// to get the color tweener to work, import ColorShortcuts properties
import caurina.transitions.properties.ColorShortcuts;
// initiate the ColorShortcuts
ColorShortcuts.init();

// define a spite
var mySprite:Sprite = new Sprite();
mySprite.x = 50;
mySprite.y = 50;
mySprite.graphics.lineStyle();
mySprite.graphics.beginFill(0xff0000);
mySprite.graphics.drawRect(0,0,200,100);
addChild(mySprite);

// add the mouse actions
mySprite.buttonMode = true;
mySprite.addEventListener(MouseEvent.MOUSE_OVER, makeBlue);
mySprite.addEventListener(MouseEvent.MOUSE_OUT, makeRed);

// define the interactive effects
function makeBlue(e:MouseEvent):void{
Tweener.addTween(mySprite, {_color:0x0000ff, time:1, transition:"easeOutQuart"});
}
function makeRed(e:MouseEvent):void{
Tweener.addTween(mySprite, {_color:null, time:1, transition:"easeOutQuart"});
}

Loop through child movie clips in AS3 and AS2

To iterate through all children in a display object container…

ActionScript 3 Code Sample:

for(var i=0; i

ActionScript 2 Code Sample:

for (var Item in Parent) {
	if (typeof (Parent[Item]) == "movieclip") {
		Parent[Item].doSomething();
	}
}

Problem targeting Child MovieClip by name in AS3

import flash.display.Sprite;
import flash.display.DisplayObject;

var container:Sprite = new Sprite();

var sprite1:Sprite = new Sprite();
sprite1.name = "sprite1";
var sprite2:Sprite = new Sprite();
sprite2.name = "sprite2";

container.addChild(sprite1);
container.addChild(sprite2);

var target:DisplayObject = container.getChildByName("sprite1");
trace(container.getChildIndex(target)); // 0

Flash AS3 Webservice Solution

I recommend downloading a webservice component from WellConsidered.be to be used with the sample code below:

Sample AS3 Code:

import be.wellconsidered.services.WebService;
import be.wellconsidered.services.Operation;
 
import be.wellconsidered.services.events.OperationEvent;
 
var ws = new WebService("http://www.webservicex.net/WeatherForecast.asmx?wsdl");
var op:Operation = new Operation(ws);
 
op.addEventListener(OperationEvent.COMPLETE, onResult);
op.addEventListener(OperationEvent.FAILED, onFault);
 
op.GetWeatherByPlaceName("new york");
 
function onResult(e:OperationEvent):void { trace(e.data); }
function onFault(e:OperationEvent):void { trace(e.data); }

Download AS3 Web-service Component Here:

http://www.wellconsidered.be/blog/as3-webservice-component/

How to include a web page in to another

Server Side Includes

SSI, or Server Side Includes: Use to include html files.
<!–#include virtual=”path to file/include-file.html” –>

PHP

PHP is a server side programming language: Use this to inlcude php pages or html pages

Simple:
<?php include(“your_file.html”); ?>
Or
<?php
require($DOCUMENT_ROOT . “your_file.html”);
?>

ASP

Active Server Pages are server side programming languages: Use this to inlcude asp pages or html pages
<!–#include file=”your_file.html”–>

JavaScript

JavaScript is a client side programming language (processed by your browser, no the server): You must take your html code, place it in side of a javascript document.write function to be printed to the screen. Be sure to fix your html quote marks by adding a backslash to the front of each one.  Save the file and include it using below.

<script type=”text/javascript” src=”your_file.js”> </script>

AS3 Pass Variable to FlashVars using LoaderInfo

Unlike AS2, you can nolonger access embeded flashVars from _root using Actionscript 3. You must now using LoaderInfo.

function loaderComplete(myEvent:Event)
{
  var flashVars=this.loaderInfo.parameters;
  userNameTextField.text=flashVars.userName;
}
this.loaderInfo.addEventListener(Event.COMPLETE, loaderComplete);

What is a FlashVar?
FlashVars are nothing more than a list of variables structured as a Query Strings of data (flash.swf?user=bob&pass=123). It’s a way to pass variables from html to a Flash movie.