1. Get some images. Rename them as follows. 5A.jpg","img1.jpg","img3.jpg","img6.jpg","img7.jpg"
2.draw a shape using rectangle tool.1px X 1px. this would become the image stage.
3. convert the rectangle into Movie clip and give the instance name as "frame_mc".pivot point should be the center.
4. put the following code into ur action script panel on the first frame.
You can put any amount of images as u like.Enjoy.
//-----------------------------------------------------------------------------------
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
var loader:Loader = new Loader();
var array:Array = new Array("5A.jpg","img1.jpg","img3.jpg","img6.jpg","img7.jpg");
var url:URLRequest = new URLRequest(array[0]);
var a:Number = 0;
var xval:Number;
var yval:Number;
btn.x = (stage.stageWidth - loader.width)/2;
loader.load(url);
loader.alpha = 0;
frame_mc.alpha = 0;
loader.contentLoaderInfo.addEventListener(Event.INIT, getWidth);
function getWidth(e:Event) {
frame_mc.alpha = 1;
loader.x = (stage.stageWidth - loader.width)/2;
loader.y = (stage.stageHeight - loader.height)/2;
// drawing a border to image-------------------------------------------------
frame_mc.x = (stage.stageWidth)/2;
frame_mc.y = (stage.stageHeight)/2;
var myTween1:Tween = new Tween(frame_mc, "width", Elastic.easeOut, frame_mc.width, loader.width+10, 0.75, true);
var myTween2:Tween = new Tween(frame_mc, "height", Elastic.easeOut, frame_mc.height, loader.height+10, 0.75, true);
myTween1.addEventListener(TweenEvent.MOTION_FINISH, addLoader)
function addLoader(e:TweenEvent){
var myTween:Tween = new Tween(loader, "alpha", Regular.easeIn, 0, 1, 0.5, true);
addChild(loader);
btn.addEventListener(MouseEvent.CLICK, loadNext);
}
}
function loadNext(e:MouseEvent) {
if (a>=4) {
a=-1;
}
a = a+1;
removeChild(loader);
url = new URLRequest(array[a]);
loader.load(url);
xval = loader.width;
yval = loader.height;
btn.removeEventListener(MouseEvent.CLICK, loadNext);
}
Wednesday, May 27, 2009
Tuesday, May 26, 2009
Ditect loader dimension after loading a movie or an Image
1. save ur FLA file and place an image in the same folder.
2. rename the image as "5A.jpg". ( As im using in the example)
3. paste the following code in ur action script panel.
//----------------------------------------------------------------------------
var loader:Loader = new Loader()
var url:URLRequest = new URLRequest("5A.jpg")
loader.load(url);
loader.contentLoaderInfo.addEventListener(Event.INIT, getWidth)
function getWidth(e:Event){
loader.x = (stage.stageWidth - loader.width)/2
loader.y = (stage.stageHeight - loader.height)/2
addChild(loader)
}
//----------------------------------------------------------------------------
2. rename the image as "5A.jpg". ( As im using in the example)
3. paste the following code in ur action script panel.
//----------------------------------------------------------------------------
var loader:Loader = new Loader()
var url:URLRequest = new URLRequest("5A.jpg")
loader.load(url);
loader.contentLoaderInfo.addEventListener(Event.INIT, getWidth)
function getWidth(e:Event){
loader.x = (stage.stageWidth - loader.width)/2
loader.y = (stage.stageHeight - loader.height)/2
addChild(loader)
}
//----------------------------------------------------------------------------
Wednesday, May 20, 2009
AS 3 - simple for loop
1. Create a Movie Clip and Export it ti Action Script using linkage.call it Mc.
2. paste the following code in ur timeline.
for (var i:Number = 0; i<20; i++){
var mc:Mc = new Mc()
addChild(mc)
mc.x = mc.x + 50*i;
if (i>4){
mc.x = -250;
mc.x = mc.x + 50*i;
mc.y = 50
}
if(i>9){
mc.x = -500;
mc.x = mc.x + 50*i;
mc.y = 100
}
if(i>14){
mc.x = -250;
mc.x = mc.x + 50*i;
mc.y = 150
}
}
2. paste the following code in ur timeline.
for (var i:Number = 0; i<20; i++){
var mc:Mc = new Mc()
addChild(mc)
mc.x = mc.x + 50*i;
if (i>4){
mc.x = -250;
mc.x = mc.x + 50*i;
mc.y = 50
}
if(i>9){
mc.x = -500;
mc.x = mc.x + 50*i;
mc.y = 100
}
if(i>14){
mc.x = -250;
mc.x = mc.x + 50*i;
mc.y = 150
}
}
Wednesday, May 13, 2009
Tint MovieClip using AS 3
/* create a movie clip and name it as "mc".(instant name).Paste the following code in the timeline.ur movie clip will turn in to red(0xFF0000).Change the values as u like and try. */
import fl.motion.Color;
var aa:Color = new Color();
aa.setTint(0xFF0000, 0.9);
mc.transform.colorTransform = aa;
import fl.motion.Color;
var aa:Color = new Color();
aa.setTint(0xFF0000, 0.9);
mc.transform.colorTransform = aa;
Simple XML Loding in Action Script 3
var urlloader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var url:URLRequest = new URLRequest("images.xml");
urlloader.addEventListener(Event.COMPLETE, loadXMLhandler);
urlloader.load(url)
function loadXMLhandler(e:Event){
xmlData = new XML(e.target.data)
trace(xmlData)
}
//images.xml should be in the same folder to load
var xmlData:XML = new XML();
var url:URLRequest = new URLRequest("images.xml");
urlloader.addEventListener(Event.COMPLETE, loadXMLhandler);
urlloader.load(url)
function loadXMLhandler(e:Event){
xmlData = new XML(e.target.data)
trace(xmlData)
}
//images.xml should be in the same folder to load
Subscribe to:
Posts (Atom)