Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Class File that is used by the flash file to birth Objects ?

  • 02-12-2010 10:15PM
    #1
    Registered Users, Registered Users 2 Posts: 23


    Hi Everybody...

    I'm relatively new to this and having a difficult time. I have built a image gallery with xml in ActionScript 3.0 that has 2 columns of thumbnails to pick from. Is there any way i can convert my .fla file to an .As file so the class file can be used to birth objects on the main timeline ?

    My Xml code is

    <? xml version="1.0" encoding="utf-8"?>


    <images>
    <image source="images/Image1.jpg" thumb="thumbnails/Image1.jpg">All Smiles.</image>
    <image source="images/Image2.jpg" thumb="thumbnails/Image2.jpg">Enoying the live show.</image>
    <image source="images/Image3.jpg" thumb="thumbnails/Image3.jpg">Dinner Outside.</image>
    <image source="images/Image4.jpg" thumb="thumbnails/Image4.jpg">A couple at the Speech.</image>
    <image source="images/Image5.jpg" thumb="thumbnails/Image5.jpg">Having A Dance.</image>
    <image source="images/Image6.jpg" thumb="thumbnails/Image6.jpg">Having A Dance.</image>
    <image source="images/Image7.jpg" thumb="thumbnails/Image7.jpg">Street Performer.</image>
    <image source="images/Image8.jpg" thumb="thumbnails/Image8.jpg">High Brow.</image>

    </images>


    My Flash file Code is

    var imageLoader:Loader;
    var xml:XML;
    var xmlList:XMLList;
    var xmlLoader:URLLoader = new URLLoader();

    var numClips:int=6;
    var columns:int=2;

    xmlLoader.load(new URLRequest("data/images.xml"));

    xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

    function xmlLoaded(event:Event):void
    {
    xml = XML(event.target.data);
    xmlList = xml.children();
    for(var i:int = 0; i < xmlList.length(); i++)
    {
    imageLoader = new Loader();
    imageLoader.load(new URLRequest(xmlList.attribute("thumb")));
    imageLoader.x = 6 +( i % columns )*600;
    imageLoader.y = 6 +(Math.floor(i/columns)*106);
    imageLoader.name = xmlList.attribute("source");
    addChild(imageLoader);
    imageLoader.addEventListener(MouseEvent.CLICK, showPicture);
    }

    }


    function showPicture(event:MouseEvent):void
    {

    imageLoader = new Loader();
    imageLoader.load(new URLRequest(event.target.name));
    imageLoader.x = 158;
    imageLoader.y = 6;
    addChild(imageLoader);



    }

    the code that i am trying to use on my new .fla file so that an .As class file can be used to birth objects on the main timeline is

    import classes.interactive.gallery.ImageGallery;
    var gallery:ImageGallery = new ImageGallery("data/images.xml","thumb","full");
    addChild(gallery);


    The code in my .As file is just a regular template where i dont know where to begin......


    package
    {
    import flash.display.*;
    import flash.events.*;
    import fl.transitions.*;
    import fl.transitions.easing.*;

    public class ImageGallery extends MovieClip
    {


    public function ImageGallery()
    {

    }

    }
    }


    Please help :confused:.Any feedback would be a great help


Comments

  • Registered Users, Registered Users 2 Posts: 2,119 ✭✭✭p


    It is possible. At a high level, you need to create a Class for your main Flash file. (You can do this in the properties panel) The second thing is to create a Class that you want multiple instances of.

    I'd recommend doing a test, by setting up a basic structure, where you have a main class, and you can create multiple instances of another class, something like a Ball, and use the main class do something like new Ball("blue", 50); with different variables. If you can get to that stage, you can then try create something like an ImageHolder class, that loads a targetted image, and a LargeImage class that contains the full size image. You can then try get them to talk to each other.

    I'd suggest you try read up on a few Flash Class/OO tutorials to get you up to speed.
    http://www.flashandmath.com/bridge/intro/
    http://www.senocular.com/flash/tutorials/as3withflashcs3/?page=1
    http://www.adobe.com/devnet/actionscript/articles/oop_as3.html

    Good luck!


Advertisement