Tutorial to Create a Responsive Image Scroller in ActionScript 3.0

responsive-images-scroller-as3-thumb

I’ve written a tutorial which is published over at flash.tutsplus. This tutorial demonstrates how to create a horizontally scrolling image viewer and covers xml parsing, loading and resizing external images, and creating intuitive and responsive scrolling!

Get Adobe Flash player

So check out the Tutorial to Create a Responsive Image Scroller in ActionScript 3.0 over at flash.tutsplus.com!

sourcedemomilestone

You’ll find full source code available for download as well as the demo files and step by step milestones all throughout the tutorial.

This entry was posted in portfolio, review, tutorial and tagged , , , , , , , , , , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

7 Comments

  1. alexandru
    Posted August 27, 2009 at 9:05 am | Permalink

    hi. i am going to copy/paste the post i posted on flashtuts, maybe you can help me:
    “hello,
    very nice tut, very well explained. i do have one question. let’s say i already have created a ’scroller’ which has a nice look, and i’ve already placed some containers for thumbnails in the scroller. what would be the simpliest code to load pictures from xml into those specific containers? (everything else, including movement is done separately)
    i will start with this:
    var xmlLoader:URLLoader = new URLLoader();
    var xmlData:XML = new XML();
    var xmlPath:String = “pictures_xml.xml”;
    xmlLoader.load(new URLRequest(xmlPath));
    this part is enough for loading the xml, correct? (let’s say that the pictures are small enough so i will not need the complete event listener.)
    what i need now is to put the infos from xml into my scroller and make so that when i press one image i got the big one loaded into a different container. and here i got stucked.
    can you, please, help me? you can name however you want the containers and the scroller.
    thanks you very much,
    alex”

  2. Prateek Nagar
    Posted December 30, 2009 at 5:31 am | Permalink

    Hii all, I m going to perform a Drag and Drop intractivity using ActionScript 3.0.
    I m going to perform drag n drop of images which are loading into a movieclip and then i m trying to apply the drag n drop logic but i m facing a trouble as loader class is used in loading external images and startDrag() and stopDrag() method cannot be applied on loader type object it should either be applied on a movieclip object or on Sprite type object. Here is my source code that i m working on. Please help me as soon as possible :
    package DND
    {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Loader
    import flash.display.MovieClip
    import flash.display.Sprite;
    import flash.events.MouseEvent
    import flash.events.Event
    import flash.net.URLLoader
    import flash.net.URLRequest
    import flash.text.TextField
    import flash.display.DisplayObject
    import flash.display.DisplayObjectContainer
    import flash.display.Sprite

    public class dnd extends MovieClip
    {
    public var startX:Number;
    public var startY:Number;
    public var xmlData:XML
    public var tf:TextField
    public var loader1:Loader = new Loader()
    public var loader2:Loader = new Loader()
    public var loader3:Loader = new Loader()
    private var url1:String = “image1.png”
    private var url2:String = “image2.png”
    private var url3:String = “image3.png”
    public var placeHolder_mc1:MovieClip = new MovieClip;
    public var placeHolder_mc2:MovieClip = new MovieClip;
    public var placeHolder_mc3:MovieClip = new MovieClip;
    public var target_img1:MovieClip
    public var target_img2:MovieClip
    public var target_img3:MovieClip
    public var aSprite:Sprite = new Sprite();
    public var aSprite2:Sprite = new Sprite();
    public var aSprite3:Sprite = new MovieClip();

    public function dnd():void
    {
    var xml:URLLoader = new URLLoader();
    xml.addEventListener(Event.COMPLETE, callXML);
    xml.load(new URLRequest(“DND.xml”));
    }

    public function callXML(e:Event):void
    {
    var loader:Loader = new Loader()
    xmlData = new XML(e.target.data);
    var imgNode:XMLList = xmlData.images.img.(@id == “0″);
    trace(“IMG 1::” + imgNode);
    var request1:URLRequest = new URLRequest(imgNode);
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
    loader.load(request1);

    //——————————————————————–
    /*xmlData = new XML(e.target.data);
    //(xmlData);
    var imgNode1:XMLList = xmlData.images.img.(@id == “0″);
    var imgNode2:XMLList = xmlData.images.img.(@id == “1″);
    var imgNode3:XMLList = xmlData.images.img.(@id == “2″);
    //trace(imgNode);
    var request1:URLRequest = new URLRequest(imgNode1)
    var request2:URLRequest = new URLRequest(imgNode2)
    var request3:URLRequest = new URLRequest(imgNode3)
    var tempClip:MovieClip = new MovieClip();
    loader1.load(request1)
    loader2.load(request2)
    loader3.load(request3)

    placeHolder_mc1.addChild(loader1)
    placeHolder_mc2.addChild(loader2)
    placeHolder_mc3.addChild(loader3)
    loader1.x = 50
    loader2.x = 150
    loader3.x = 250
    tempClip.addEventListener(MouseEvent.CLICK, pickUp);
    loader1.contentLoaderInfo.addEventListener(Event.COMPLETE,onCompleteHandler1)
    placeHolder_mc1 = loader1.content as MovieClip;
    placeHolder_mc2 = loader2.content as MovieClip;
    placeHolder_mc3 = loader3.content as MovieClip;
    //placeHolder_mc1.addEventListener(MouseEvent.CLICK,pickUp)
    //placeHolder_mc1.addEventListener(MouseEvent.CLICK,dropIt)
    placeHolder_mc2.addEventListener(MouseEvent.CLICK,pickUp)
    placeHolder_mc2.addEventListener(MouseEvent.CLICK,dropIt)
    placeHolder_mc3.addEventListener(MouseEvent.CLICK,pickUp)
    placeHolder_mc3.addEventListener(MouseEvent.CLICK,dropIt)*/

    }
    public function onComplete(e:Event):void
    {
    //var bmp:BitmapData = BitmapData(e.target.content)
    //trace(“BMP::” + bmp);
    //trace(e.currentTarget.content);
    //——————————————————–
    //———Dummy Code———————————–

    aSprite.graphics.clear();
    aSprite.graphics.beginFill(0xFFFFFF,1);
    aSprite.graphics.drawRect(0,0,100,100);
    aSprite.graphics.endFill();
    aSprite.x=30;
    aSprite.y=40;
    addChild(aSprite);
    var bitmap:Bitmap=e.target.loader.content as Bitmap;
    bitmap.x=30;
    bitmap.y=40;
    aSprite.addChild(bitmap);

    aSprite2.graphics.clear();
    aSprite2.graphics.beginFill(0xFF0000,1);
    aSprite2.graphics.drawRect(0,0,100,100);
    aSprite2.graphics.endFill();
    aSprite2.name=”source_mc”;
    aSprite2.x=400;
    aSprite2.y=70;
    addChild(aSprite2);

    aSprite3.graphics.clear();
    aSprite3.graphics.beginFill(0×000000,1);
    aSprite3.graphics.drawRect(0,0,100,100);
    aSprite3.graphics.endFill();
    aSprite3.name=”targetsource_mc”;
    aSprite3.x=200;
    aSprite3.y=200;
    addChild(aSprite3);
    aSprite.addEventListener(MouseEvent.MOUSE_DOWN,pickUp);//dragInit
    aSprite.addEventListener(MouseEvent.MOUSE_UP,dropIt);//dragRemove
    aSprite2.addEventListener(MouseEvent.MOUSE_DOWN,pickUp);
    aSprite2.addEventListener(MouseEvent.MOUSE_UP,dropIt);

    }
    public function pickUp(event:MouseEvent):void
    {
    /*trace(“hello1″);
    placeHolder_mc1.startDrag();
    placeHolder_mc1.hitTestObject(target_placeHolder1_mc)
    trace(“hit …?” + target_placeHolder1_mc)
    reply_txt.text = “”;*/
    //trace(e.target.content);
    //trace(“tempClip created type ::” + event.target);
    event.target.startDrag(true);
    event.target.parent.addChild(event.target);
    startX = event.target.x;
    startY = event.target.y;
    }
    public function dropIt(event:MouseEvent):void
    {
    event.target.stopDrag();
    var myTargetName:String = “target” + event.target.name;
    //trace(“myTargetName ::” + myTargetName);
    var myTarget:DisplayObject = getChildByName(myTargetName);
    trace(“mera Target ::” + myTarget);
    if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget)
    {
    event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
    event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
    event.target.buttonMode = false;
    event.target.x = myTarget.x;
    event.target.y = myTarget.y;
    } else
    {
    event.target.x = startX;
    event.target.y = startY;
    }
    }
    }
    }

    • Posted December 30, 2009 at 10:13 am | Permalink

      @Prateek -

      I m going to perform drag n drop of images which are loading into a movieclip and then i m trying to apply the drag n drop logic but i m facing a trouble as loader class is used in loading external images and startDrag() and stopDrag() method cannot be applied on loader type object it should either be applied on a movieclip object or on Sprite type object.

      You solved it already basically, just put the loader into a container movieclip and then you’ll be able to apply the drag and drop logic to them. That or you can re-parent the contents of the loader object to any display object on loadcomplete and it will rid you of the loader object altogether.

  3. P P Vilsad
    Posted January 3, 2010 at 12:48 am | Permalink

    Hi,
    The tutorial and the source code is not available in the link you gave. pls check it. infact there is nothing showing if i type flash.tutsplus.com

    • Posted January 5, 2010 at 3:57 pm | Permalink

      It’s actually changed to active.tutsplus.com – funny they dont redirect or anything. Thanks for finding it, I’ll update the link.

  4. ed
    Posted June 24, 2010 at 2:55 am | Permalink

    This is very useful.

    I just had one problem, while trying it.
    What if the images I have has different “width”, and I don’t want it to be in the “box” (say in here 140), and I just want the space between the images is the “padding”.

    I hope you can help.
    Thanks again.

  5. justin
    Posted July 12, 2010 at 3:41 pm | Permalink

    How can I make this into a vertical slider?

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Recent Posts

    pears-circlecube-com-welcome

    LESS and syntax highlighting for Pea.rs

    Pears is an open source WordPress theme by Dan Cederholm (simplebits), enabling people like us to get your own pattern library up and running quickly. Collect, test, and experiment with interface pattern pairings of CSS & HTML. I’ve customized pears. I’ve forked it, adding support for coding in LESS as well as code highlighting! The [...]

    2012-02-10-19-27_IMAG0181

    An Event Apart Atlanta 2012 Notes

    Here is my collection of notes from attending An Event Apart Atlanta 2012. As I took notes, I had the thought that I’d be sharing them with co-workers and that it’d be easiest to just publish them here. I hope they are useful to someone else out there who didn’t take notes on something or [...]

    Developing for old browsers is (almost) a thing of the past – (37signals)

    Basecamp announces that it’s new version will not support old browsers! They will of course continue to support them in their “classic” version. But this is good news and as more implement this type of policy the internet will be happy. It used to be one of the biggest pains of web development. Juggling different [...]

    Screen shot 2012-02-10 at 12.59.33 PM

    Vendor Prefixes – about to go south

    What are “standards” coming to? Who’s guilty? Apple and Chrome: They’re supporting vendor prefixed properties like they’re a standard part of development. Firefox, Opera and Internet Explorer: They should have been on the ball more. Need to push their evangelism further. Teach developers that it’s not exclusively -webkit to style elements. All the browsers: experimental [...]

    bio

    An Event Apart Notes: Ethan Marcotte, Responsive Web Design

    Ethan Marcotte has become the father of Responsive Web Design and spent this whole day focused on principles, techniques, gotchas, examples, … all about building and how to build responsive sites. With a sprinkle of mobile first. For Ethan, it all started with this article: http://www.alistapart.com/articles/dao/ Think of architecture, the whole design phase is established [...]

    Webcomm_Montreal

    An Event Apart Notes: Jared Spool, The Curious Properties of Intuitive Web Pages

    Senseless waste of asterisks… Avis used an asterisk to denote optional fields. This means that there is a lot of baggage that comes with an asterixk. Somewhere this symbol got meaning, it’s not in the bible! We can control when something goes from unintuitive to intuitive. A design is intuitive (although technically and grammatically speaking [...]

    untitled-158-2

    An Event Apart Notes: Marco Arment, Bridging the App Gap

    The iPhone changed our industry in 2007: first mobile to have a desktop class web browser and it made people start using their mobile phones as computers! All apps other than apple provided ones were web browser apps. Most of the first apps were branded web browsers. No real difference between using mobile site or [...]

    lukew_space

    An Event Apart Notes: Luke Wroblewski, Mobile to the Future

    MASS MEDIA (in waves) Print, Recordings, Cinema, Radio, Television, Internet, Mobile Mobile is the new Mass Media It certainly is mass and massive. More mobile devices (by far) every day than babies born on the planet. Mobile devices are eating into our personal computing shares. New waves of mobile media eat all previous media waves. [...]

    IMG_4500

    An Event Apart Notes: Josh Clark, Buttons are a Hack

    Mobile and touch should be revolutionizing design and user experience. We don’t want to touch a tiny link or button. Back button is just stupid. Fitz’s Law, make things fat proximal targets for easy touching. People are lazy, let’s as designers LET people be lazy! Maybe even use the whole screen as your control. Eliminate [...]

    nicole_pink_bkg_2012

    An Event Apart Notes: Nicole Sullivan, Our Best Practices are Killing Us

    Grep to for analyze css. CSS duplication is a web-wide problem. Started helping facebook optimize thier site and they had 1.9MB of css loading. The same color showing up hundreds of times. Many many color statements and declarations. !important declarations get dangerous. Sites found to have over 500 !important declarations! float is a serious problem [...]

  • Recent Comments

    Evan Mullins

    Evan Mullins

    @Mikael – I believe this would do it. It just fired the toggle event on the...
    Mikael

    Mikael

    Hey great post!! can i by any chance make the toggle function start as hidden? So when i reload...
    Ori

    Ori

    you saved me man :) !!!! thank you
    me-gamer

    me-gamer

    this is really nice. this made many of my task simple.
    Lori Newman

    Lori Newman

    Just wanted to thank you for your presentation. It was extremely informative and just what I...
    Karl

    Karl

    I have been using for some time this nice Banner, from developer FX. They have a really nice Live...