You must be logged in to post Login Register
Search 

Flash Infinite Gallery Tutorial

User Post

1:48 pm
January 13, 2010


dailyunnamed

New Member

posts 1

1

Hi all,

I was wondering if anyone would be able to help me out. I've been following the tutorial at: http://tutorials.flashmymind.c…..lery-menu/ and I was wondering how I would go about adding a function to each of these buttons where they could open an image file or something such as another .swf?

Any help would be greatly appreciated!

Many thanks

4:03 pm
February 2, 2010


Inter-Reality

Member

Netherlands

posts 7

2

hi dailyunnnamed,

Pretty nice solution is to use image definitions aand adding an eventlistener to the swf files. For instance for each movieclip that is held in

infiniteGallery would be called by saying:
var speed:Number = 0;

//Add around this point
var stageImageHolder:MovieClip = new MovieClip();

infiniteGallery.movieClip1.name = “m1″
infiniteGallery.movieClip1.addEventListener(mouseEvent.CLICK, getTarget);

//then define the getTarget function with a loader for instance:

function getTarget(imgEvent:mouseEvent):void

{
var loader:Loader = new Loader();
        stageImageHolder.addChild (loader);
        loader.load (new URLRequest(“directory with images stored” + imgEvent.name + “.jpg”));
        loader.contentLoaderInfo.addEventListener (Event.INIT, imageLoaded);

        function imageLoaded (evt:Event):void
        {

            //loader.contentLoaderInfo.removeEventListener (Event.INIT,imageLoaded);

            var loaderInfo:LoaderInfo = evt.target as LoaderInfo;
            var dispObj:DisplayObject = loaderInfo.content;

            var thisWidth = dispObj.width;
            var thisHeight = dispObj.height;

            var maxW = 320;
            var maxH = 240;
            var _ratio = thisHeight / thisWidth;
            if (thisWidth > maxW)
            {
                thisWidth = maxW;
                thisHeight = Math.round(thisWidth * _ratio);
            }
            if (thisHeight > maxH)
            {
                thisHeight = maxH;
                thisWidth = Math.round(thisHeight / _ratio);
            }
            dispObj.width = thisWidth;
            dispObj.height = thisHeight;
            dispObj.x=(maxW-dispObj.width)/2;
            dispObj.y=(maxH-dispObj.height)/2;
        }

}


This is a rough painting of a script you could look at…

happy coding!


Cool

inter-reality.com – the true art of coding

Inter-Reality – the true art of coding http://www.inter-reality.nl

Topic RSS 
Search