Roll over effect for the ThumbnailScroller
Actionscript 3, Flash Components, Tutorials January 11th, 2008In this tutorial you will see how easy it is to add a roll over effect to the ThumbnailScroller Component. For this example I will add a blur effect using the Tweener class.
1. Drag an instance of the ThumbnailScroller Component on the stage and give it the instance name “myScroller”. In the Component Inspector you have to give the component the path of the XML file(thumbnails.xml). Optionally, you can change the other properties how you like. For this example, I will change border to true, border thickness to 5, easing type to Back, easing method to easeInOut and the move amount to 200.
2. Create 2 movie clips that will help you move the thumbnails right or left and give them the instance name “right” and “left”.
3. Add a new layer in which you will put your actionscript code.
First, we need to import the ThumbnailEvent class and the Tweener class(find more information about Tweener here)
-
import com.flashotaku.thumbnailscroller.events.ThumbnailEvent;
-
import caurina.transitions.Tweener;
Add the event listeners for the “right” and “left” movie clips:
-
left.addEventListener(MouseEvent.CLICK, leftHandler);
-
right.addEventListener(MouseEvent.CLICK, rightHandler);
-
-
function leftHandler(event:MouseEvent){
-
myScroller.moveLeft();
-
}
-
-
function rightHandler(event:MouseEvent){
-
myScroller.moveRight();
-
}
Before adding the roll over and roll out effect, we want to add blur to each thumbnail when it’s added to the stage. For this, add this code:
-
myScroller.addEventListener(ThumbnailEvent.THUMB_INIT, addBlur);
-
-
function addBlur(event:ThumbnailEvent){
-
Tweener.addTween(event.item.child, {_blur_blurX:5, _blur_blurY:5, _blur_quality:2, time:.1, transition:"linear"});
-
}
Finally, add the code for the roll over and roll out effects:
-
myScroller.addEventListener(ThumbnailEvent.MOUSE_OVER, rollOverBlur);
-
myScroller.addEventListener(ThumbnailEvent.MOUSE_OUT, rollOutBlur);
-
-
function rollOverBlur(event:ThumbnailEvent){
-
Tweener.addTween(event.item.child, {_blur_blurX:0, _blur_blurY:0, _blur_quality:2, time:.3, transition:"linear"});
-
}
-
-
function rollOutBlur(event:ThumbnailEvent){
-
Tweener.addTween(event.item.child, {_blur_blurX:5, _blur_blurY:5, _blur_quality:2, time:.3, transition:"linear"});
-
}
The result is this:
If you have any questions, fell free to ask.
Download files for Actionscript 3
Download files for Actionscript 2
Support
As of 11 March 2009, support is no longer provided for the free components. If you need support, please purchase the commercial version of the components.
January 21st, 2008 at 1:45 am
Hi there, once again it’s a really nice component- how hard would it be to make each thumbnail a button that calls upon a URL placed inside the XML file?
Thanks in advance!
January 21st, 2008 at 12:30 pm
Hi Darren, I’ve made a new tutorial that shows how to do that. http://flashotaku.com/blog/open-url-when-a-thumbnail-is-clicked/
January 26th, 2008 at 9:30 pm
I am looking for a way to scale the thumbs when rolled over, but the icon index is the top left corner. Is there a way to change that?
January 28th, 2008 at 12:03 pm
You can’t change the registration point of the thumbnails but you could move them up and left when you scale them. This way it would look like the registration point is in the center.
February 6th, 2008 at 3:50 am
Is it possible to make the center thumbnail 100% while keeping the others at 80% por example, I mean have the current center thumbnail to “grow” when focused, and shrink it to the left after a button click?
This code makes basically that but it biuld an array of movie clips to work with instead of pulling them from a XML file like yours.
this.redraw = function(p_immediate:Boolean) {
// Redraws every item on their new position
var i:Number;
var scaleSmall:Number = 0.2; // Scale when not focused
var scaleBig:Number = 0.6; // Scale when focused
var baseX:Number = 250; // Base column for focused position
var baseY:Number = 135; // Base row for all icons
var iconDistance:Number = 80; // Distance between the center axis of each icon
var iconDistanceFocused:Number = 140; // Distance between the center axis of each icon WHEN FOCUSED
var animationTime:Number = p_immediate ? 0 : 0.3;
var animationType:String = “easeoutback”;
// Redraw: icons
// Set correct scale
for (i = 0; i 1 ? scaleSmall : ((1-Math.abs(distance)) * (scaleBig-scaleSmall)) + scaleSmall;
var itemX:Number = baseX + (distance * -iconDistance);
if (distance != 0) {
itemX += (iconDistanceFocused – iconDistance) * (distance > 0 ? -1 : +1);
}
Tweener.addTween(this.icons[i], {_x:itemX, _xscale:100 * itemScale, _yscale:100 * itemScale, time:animationTime, transition:animationType});
this.icons[i]._y = baseY;
February 6th, 2008 at 8:48 am
This component is not optimized for adding effects that modify the x, y, width and height of thumbnails, so I wouldn’t recommend using a scale effect for this component.
March 5th, 2008 at 3:08 pm
Great tutorial, is posible to alter the properties of one particular thumbnail from a external source?
I have the thumbnailScroller included in a greater component like the “another gallery” of yours, and I want that the thumbnails appear with 0.2 alpha, but the selected one (current showing in the app) to be with 1 alpha, can i control that behavior?
March 5th, 2008 at 5:04 pm
I’m not sure if it’s what you need but I’ve built an example
http://flashotaku.com/files/scroller_effect.zip
March 5th, 2008 at 5:22 pm
That’s exactly what I need, I tryed to implement it in my app but its not working correctly, when i click in another thumbnail the last one keeps at alpha 1 until i roll the mouse over it, in that case it returns to the desired alpha, why could that be happening?
And another thing, in the example you built, the change is expected from a mouse action, how can i implement the same from another source? I do know the id of the thumb that i need to be highlighted, but the “event” would be fired from a source that can’t use the event.child.. I’m not sure if you understand me..
March 5th, 2008 at 7:34 pm
to get a certain thumbnail without using the ThumbnailEvent class you need to know the internal structure of the component
add this code:
//thumbnails' containervar container:Sprite = myScroller.getChildAt(0) as Sprite;
//the thumbnail you wantvar myThumbnail:Sprite = container.getChildAt(id) as Sprite;
March 5th, 2008 at 9:17 pm
Great, thank you.. I have to experiment a bit with that to get the effects I need, thank you again, the components you’ve developed are really nice.
March 21st, 2008 at 6:05 pm
Is there a way to mark the thumbnails to correspond with the current large image?
So for example the current image’s thumbnail will have a lower alpha than the others until another thumbnail is selected.
March 21st, 2008 at 7:07 pm
See this example http://flashotaku.com/files/scroller_effect.zip
March 21st, 2008 at 11:10 pm
Awesome, Thanks!
April 15th, 2008 at 8:54 pm
When I dont use the left and right button but mouse scroll, the effect only starts after click event, how can I get it to start on load? Btw just what I was looking for…
April 15th, 2008 at 10:29 pm
MisterCrash,
That’s strange. Maybe you could post your code or send me the files to check.
April 16th, 2008 at 1:13 pm
I’m shure I must have made a stupid mistake, cause I’m a copy-paste-trial-error kinda guy. Using the alpha-key in here and when I load the scroller it displays images at full alpha untill first click, they turn down the alpha on rollover.
import com.flashotaku.thumbnailscroller.events.ThumbnailEvent;
import caurina.transitions.Tweener;
import flash.display.DisplayObject;
myScroller.addEventListener(ThumbnailEvent.CLICK, clickHandler);
function clickHandler(event:ThumbnailEvent){
mySlideshow.loadImage(event.item.id);
var thumbnail:DisplayObject; // this will keep a reference to the thumbnail that is clicked
myScroller.addEventListener(ThumbnailEvent.THUMB_INIT, addAlpha);
myScroller.addEventListener(ThumbnailEvent.MOUSE_OVER, rollOverAlpha);
myScroller.addEventListener(ThumbnailEvent.MOUSE_OUT, rollOutAlpha);
myScroller.addEventListener(ThumbnailEvent.CLICK, clickAlpha);
function addAlpha(event:ThumbnailEvent){
Tweener.addTween(event.item.child, {alpha:.5, time:.1, transition:”linear”});
}
function rollOverAlpha(event:ThumbnailEvent){
Tweener.addTween(event.item.child, {alpha:1, time:.3, transition:”linear”});
}
function rollOutAlpha(event:ThumbnailEvent){
if(thumbnail != event.item.child){
Tweener.addTween(event.item.child, {alpha:.5, time:.3, transition:”linear”});
}
}
function clickAlpha(event:ThumbnailEvent){
Tweener.addTween(thumbnail, {alpha:.5, time:.3, transition:”linear”});
thumbnail = event.item.child;
}}
April 16th, 2008 at 7:29 pm
It seems like you’ve misplaced a brace. :)
Delete the last brace in your code and add a closing brace after mySlideshow.loadImage(event.item.id)
It should work fine now.
April 16th, 2008 at 8:58 pm
Allright! Thx, I knew it was something like that but it all looks like chinese to me. Lol, maybe one more question; to play a flash movie instead of showing a picture is it enough to replace the .jpg in the XML to a .swf?
April 16th, 2008 at 10:10 pm
Yes, though loading a SWF is a little tricky and I wouldn’t recommend it because the movie clip could continue play even after you load a new SWF. You could still try and see how it works.
April 22nd, 2008 at 8:45 am
Hey Otaku, Crash again. I’m trying to create a extra rollover layer to move the Scroller out and back into the scene on roll out and rollover. But mixing tutorials seems to mess up my AS again. Do you have any tips?
April 22nd, 2008 at 9:49 am
Hi Crash,
Please be more specific about what you’re trying to do or post your code.
April 22nd, 2008 at 10:30 am
Well I’m trying to use the Scroller on top of the Slideshow and when I move out of the original scroller area it moves down out of sight. And when I move back into the original area it comes back into play.
I’m trying to figure out a way to use coordinates for the rollover area because using a rectangle above the Scroller disables my thumbnails.
import fl.transitions.Tween;
import fl.transitions.easing.*;
var myScrollerHome:Point = new Point(62, 297.9);
myScroller.x = myScrollerHome.x;
myScroller.y = myScrollerHome.y;
myScroller.addEventListener(MouseEvent.MOUSE_OUT, slideOutmyScroller);
myScroller.addEventListener(MouseEvent.MOUSE_OVER, slideInmyScroller);
function slideOutmyScroller(mevt:MouseEvent):void {
var twSlide:Tween;
twSlide = new Tween(myScroller, “y”, Back.easeIn, myScrollerHome.y, myScrollerHome.y + 70 , 10);
}
function slideInmyScroller(mevt:MouseEvent):void {
var twSlide:Tween;
twSlide = new Tween(myScroller, “y”, Back.easeOut, myScrollerHome.y – 0, myScrollerHome.y, 10);
}
April 22nd, 2008 at 2:51 pm
Here is the solution I’ve come up with http://flashotaku.com/files/gallery_ex4_as3.zip
April 22nd, 2008 at 9:04 pm
Awsome man, I think it’s about time I made a little donation for all your help. I’ll see what I can spare. Greetz
July 5th, 2008 at 12:33 am
A friend of mine is working on one of his first flash sites and has been doing your tutorials I think. He’s using your ThumbnailScroller component and the result is that it’s sort of hard to scroll to the thumbnail you want because the scroller is constantly scrolling when you mouseover it so it’s difficult to hit the thumbnail you want because it’s a moving target. Is there some parameter I can set on the thumbnail scroller which will make a ‘safe’ region in the center where a mouseover doesn’t cause the thumbnails to scroll?
July 5th, 2008 at 1:01 pm
Unfortunately, this is how mouse scrolling works with this component; you need to to select a thumbnail when the mouse it’s somewhere in the middle because the speed is lower then.
July 25th, 2008 at 11:03 am
Okay, after playing around a bit I got it to work, it loads the gallery and the thumbs but I did the tut above and I keep getting this:
ReferenceError: Error #1069: Property _blur_blurX not found on flash.display.Loader and there is no default value.
at caurina.transitions::Tweener$/addTween()
at MethodInfo-208()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.flashotaku.thumbnailscroller::ThumbnailScroller/::mouseOutHandler()
and there is no tween effects on the thumbs.
I could post my class here but it is way long and disorganized.
also, nothing happens when I click on the thumbs?
thanx for any help.
July 25th, 2008 at 12:09 pm
Don’t know what to say about this error. Just make sure you do exactly as in this tutorial and it should work.
July 28th, 2008 at 11:23 am
I have a box that tweens in and then I load the thumbScroller inside a content holder after the box finished it’s tween. I use the mouse scrolling thumbScroller, that works, it moves to the left and right but the thumbs are not responding when I click on them, I decided not to use the fade effect above but I need help with this scroller please.
I copied and pasted everything from that tut exactly.
July 29th, 2008 at 8:46 am
Here is the class…I give up I can’t find the problem
package
{
import flash.display.DisplayObject;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.ContextMenuEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.ui.Mouse;
import caurina.transitions.Tweener;
import com.flashotaku.slideshow.Slideshow;
import com.flashotaku.thumbnailscroller.ThumbnailScroller;
import com.flashotaku.thumbnailscroller.events.ThumbnailEvent;
import com.flashotaku.slideshow.events.SlideshowEvent;
import gs.TweenMax;
public class main extends Sprite
{
public static var origW:Number = 1024 //original stage width
public static var origH:Number = 768 //original stage height
//graphic resources
private var bg:Sprite;
private var cont:Sprite;
private var art:Sprite;
private var photo:Sprite;
private var project:Sprite;
//constructor
public function main ()
{
//Tel the player not to scale the assets
stage.scaleMode = StageScaleMode.NO_SCALE;
//Tell the player to put co-ords 0,0 to the top left corner
stage.align = StageAlign.TOP_LEFT;
//Listen for resize events
stage.addEventListener(Event.RESIZE, onResize);
//Create and add body resource to the display list
bg = new bg_mc();
addChild(bg);
cont = new content();
addChild(cont);
art = new art_mc();
cont.addChild(art);
art.x = 94.2;
art.y = 512.5;
photo = new photo_mc();
cont.addChild(photo);
photo.x = 136.1;
photo.y = 517.9;
project = new project_mc();
cont.addChild(project);
project.x = 150;
project.y = 535;
//Size everything after creation to insure the app is drawn
//properly the first time it is seen prior to any user initiated
//resizing
onResize(null);
art.addEventListener(MouseEvent.CLICK, ClickListener)
photo.addEventListener(MouseEvent.CLICK, ClickListener1)
project.addEventListener(MouseEvent.CLICK, ClickListener2)
//set button properties
art.buttonMode = true;
art.useHandCursor = true;
photo.buttonMode = true;
photo.useHandCursor = true;
project.buttonMode = true;
project.useHandCursor = true;
var box:Sprite = new Sprite;
var imageBox:Sprite = new Sprite;
var mySlideshow = new Slideshow();
var myScroller = new ThumbnailScroller();
//gallery functions
function loadGallery()
{
mySlideshow = new Slideshow();
cont.addChild(mySlideshow);
mySlideshow.xmlPath = “images.xml”;
mySlideshow.setSize(500, 380);
mySlideshow.x = 476;
mySlideshow.y = 29;
mySlideshow.setBorder = false;
mySlideshow.preloaderType = “circular”;
mySlideshow.transitionEffect = “fade”;
}
//thumbnail functions
myScroller.addEventListener(ThumbnailEvent.CLICK, clickHandler);
function clickHandler(event:ThumbnailEvent):void
{
mySlideshow.loadImage(event.item.id);
trace(event.item.id);
}
function loadThumb()
{
myScroller = new ThumbnailScroller();
cont.addChild(myScroller);
myScroller.xmlPath = “thumbnails.xml”;
myScroller.setSize(920, 70);
myScroller.x = 50;
myScroller.y = 650;
myScroller.setBorder = true;
myScroller.borderThickness = 2;
myScroller.easingType = “Back”;
myScroller.easingMethod = “easeInOut”;
myScroller.moveAmount = 100;
myScroller.mouseMove = true;
myScroller.name = “myScroller”;
}
function deleteChild():void
{
cont.removeChild(myScroller);
trace(“child removed”);
}
//tween functions
function tweenBoxIn():void
{
TweenMax.multiSequence
([
{ target:box, time:0.2, y:625 },
{ target:box, time:0.5, scaleY:12 },
{ target:box, time:1, x:35, scaleX:95, onComplete:loadThumb }
]);
}
function tweenIBoxIn():void
{
TweenMax.multiSequence
([
{ target:imageBox, time:0.5, x:466 },
{ target:imageBox, time:0.1, alpha:0.8 },
{ target:imageBox, time:1, scaleX:52 },
{ target:imageBox, time:1, y:15, scaleY:44, onComplete:loadGallery }
]);
}
function tweenBoxAgain():void
{
TweenMax.multiSequence
([
{ target:myScroller, time:1, alpha:0 },
{ target:myScroller, onComplete:deleteChild },
{ target:box, time:1, alpha:0 },
{ target:box, time:0.1, x:0, y:0, scaleX:1, scaleY:1 },
{ target:box, time:0.2, alpha:0.8 },
{ target:box, time:0.2, y:625 },
{ target:box, time:0.5, scaleY:12 },
{ target:box, time:1, x:35, scaleX:95 },
{ target:box, onComplete:loadThumb }
]);
}
//Check ClickListener
function ClickListener(event:MouseEvent):void
{
art.mouseEnabled = false;
photo.mouseEnabled = true;
project.mouseEnabled = true;
trace(“button clicked:” + event.currentTarget);
if (Boolean(cont.getChildByName(‘box’)))
{
trace(“box found”);
tweenBoxAgain();
mySlideshow.xmlPath = “images.xml”;
myScroller.xmlPath = “thumbnails.xml”;
}
else
{
trace(“no boxes found”);
box = new Sprite();
box.graphics.lineStyle(2, 0xffffff, 0.5, false, “none”);
box.graphics.beginFill(0×000000, 0.5);
box.graphics.drawRect(0, 0, 10, 10);
box.graphics.endFill();
cont.addChild(box);
box.name = “box”;
trace(“new box drawn”);
imageBox = new Sprite();
imageBox.graphics.lineStyle(2, 0xffffff, 0.5, false, “none”);
imageBox.graphics.beginFill(0×000000, 0.5);
imageBox.graphics.drawRect(0, 0, 10, 10);
imageBox.graphics.endFill();
cont.addChild(imageBox);
tweenBoxIn();
tweenIBoxIn();
trace(“new imageBox drawn”);
}
}
//Check ClickListener1
function ClickListener1(event:MouseEvent):void
{
art.mouseEnabled = true;
photo.mouseEnabled = false;
project.mouseEnabled = true;
trace(“button clicked:” + event.currentTarget);
if (Boolean(cont.getChildByName(‘box’)))
{
trace(“box found”);
tweenBoxAgain();
mySlideshow.xmlPath = “images1.xml”;
myScroller.xmlPath = “thumbnails1.xml”;
}
else
{
trace(“no boxes found”);
box = new Sprite();
box.graphics.lineStyle(2, 0xffffff, 0.5, false, “none”);
box.graphics.beginFill(0×000000, 0.5);
box.graphics.drawRect(0, 0, 10, 10);
box.graphics.endFill();
cont.addChild(box);
box.name = “box”;
trace(“new box drawn”);
imageBox = new Sprite();
imageBox.graphics.lineStyle(2, 0xffffff, 0.5, false, “none”);
imageBox.graphics.beginFill(0×000000, 0.5);
imageBox.graphics.drawRect(0, 0, 10, 10);
imageBox.graphics.endFill();
cont.addChild(imageBox);
tweenBoxIn();
tweenIBoxIn();
trace(“new imageBox drawn”);
}
}
//Check ClickListener2
function ClickListener2(event:MouseEvent):void
{
art.mouseEnabled = true;
photo.mouseEnabled = true;
project.mouseEnabled = false;
trace(“button clicked:” + event.currentTarget);
if (Boolean(cont.getChildByName(‘box’)))
{
trace(“box found”);
tweenBoxAgain();
mySlideshow.xmlPath = “images2.xml”;
myScroller.xmlPath = “thumbnails2.xml”;
}
else
{
trace(“no boxes found”);
box = new Sprite();
box.graphics.lineStyle(2, 0xffffff, 0.5, false, “none”);
box.graphics.beginFill(0×000000, 0.5);
box.graphics.drawRect(0, 0, 10, 10);
box.graphics.endFill();
cont.addChild(box);
box.name = “box”;
trace(“new box drawn”);
imageBox = new Sprite();
imageBox.graphics.lineStyle(2, 0xffffff, 0.5, false, “none”);
imageBox.graphics.beginFill(0×000000, 0.5);
imageBox.graphics.drawRect(0, 0, 10, 10);
imageBox.graphics.endFill();
cont.addChild(imageBox);
tweenBoxIn();
tweenIBoxIn();
trace(“new imageBox drawn”);
}
}
}
//listening for stage resize
public function onResize(event:Event):void
{
//get the new stage height
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;
//then update the children with this new size
bg.height = sh;
bg.width = sw;
cont.height = sh;
cont.width = sw;
}
}
}
July 29th, 2008 at 10:24 am
First of all, you don’t need to instantiate mySlideshow and myScroller outside the functions. All you need to do is:
var mySlideshow:Slideshow;
var myScroller:Scroller;
Then add the event listener for the scroller inside the loadThumb() function after you instantiate the scroller. Also, if you want to add a rollOver effect, you need to add the listeners inside the function too.
July 30th, 2008 at 6:45 am
Genius! That is why us noobs need people like you, I would never have thought about that even though it was a simple solution to my problem.
Thanx again.
July 30th, 2008 at 12:55 pm
another question if you don’t mind.
My code is basically the same as above, I only put in the piece of code from the one example where the slide show loads only after a thumb is clicked and a couple of timer events. Now I have these problems.
1. the thumbscroller and slideShow doesn’t change to another xml when the set button is clicked. I changed the button events to this.
var timer:Timer = new Timer(3200, 1);
timer.addEventListener(TimerEvent.TIMER, onTimer);
function onTimer(event:TimerEvent):void
{
mySlideshow.xmlPath = “images1.xml”;
myScroller.xmlPath = “thumbnails1.xml”;
timer.stop();
}
//Check ClickListener
function ClickListener(event:MouseEvent):void
{
art.mouseEnabled = false;
photo.mouseEnabled = true;
project.mouseEnabled = true;
trace(“button clicked:” + event.currentTarget);
if (Boolean(cont.getChildByName(‘box’)))
{
trace(“box found”);
tweenBoxAgain();
timer.start();
}
else
{
trace(“no boxes found”);
box = new Sprite();
box.graphics.lineStyle(2, 0xffffff, 0.5, false, “none”);
box.graphics.beginFill(0×000000, 0.5);
box.graphics.drawRect(0, 0, 10, 10);
box.graphics.endFill();
cont.addChild(box);
box.name = “box”;
trace(“new box drawn”);
imageBox = new Sprite();
imageBox.graphics.lineStyle(2, 0xffffff, 0.5, false, “none”);
imageBox.graphics.beginFill(0×000000, 0.5);
imageBox.graphics.drawRect(0, 0, 10, 10);
imageBox.graphics.endFill();
cont.addChild(imageBox);
tweenBoxIn();
tweenIBoxIn();
trace(“new imageBox drawn”);
}
}
I know it is probably because I tell the scroller and slideshow where to go look for the xml when I set the properties, but this code above should change the xml file shouldn’t it?
I tried leaving out the myScroller.xmlPath = “”; out of the properties but then it doesn’t load anything. I want each button to load it’s own XML
July 30th, 2008 at 1:35 pm
It should work fine if you pass it a new XML file. I think the problem could be at the “if” statement. Maybe the timer doesn’t start because the condition returns “false”. Do a trace inside the onTimer function to see if the timer actually starts.
July 30th, 2008 at 2:00 pm
The if statement does work because the tweenBoxAgain function fires every time it should and I get the trace telling me this as well. But I’ll give the trace in the ontimer a go.
I’ll let you know if it worked thanx
July 30th, 2008 at 3:52 pm
You were right, the problem was there and it’s working now.
One more though.
I want to use something like this
//whatclick function
function whatClick(MouseEvent:Event):void
{
if (event.currentTarget = ‘art’)
{
mySlideshow.xmlPath = “images.xml”;
myScroller.xmlPath = “thumbnails.xml”;
}
else if (event.currentTarget = ‘photo’)
{
mySlideshow.xmlPath = “images1.xml”;
myScroller.xmlPath = “thumbnails1.xml”;
}
else if (event.currentTarget = ‘project’)
{
mySlideshow.xmlPath = “images2.xml”;
myScroller.xmlPath = “thumbnails2.xml”;
}
}
and call the whatClick were the thumb and slide functions look for a xml file. obviously this doesn’t work. Am I going in the right direction with this or is there a better way of doing this.
Thanx for your patience
July 30th, 2008 at 4:46 pm
The direction is good but there are some syntax errors. This is the correct syntax:
//whatclick function
function whatClick(event:MouseEvent):void
{
if (event.currentTarget == art)
{
mySlideshow.xmlPath = “images.xml”;
myScroller.xmlPath = “thumbnails.xml”;
}
else if (event.currentTarget == photo)
{
mySlideshow.xmlPath = “images1.xml”;
myScroller.xmlPath = “thumbnails1.xml”;
}
else if (event.currentTarget == project)
{
mySlideshow.xmlPath = “images2.xml”;
myScroller.xmlPath = “thumbnails2.xml”;
}
}
First, the argument for the function is event of type MouseEvent. Then, in your if statements, for testing equality you use the == operator and also art, photo and project should be used without quotes because they are of type DisplayObject and not String.
July 30th, 2008 at 5:44 pm
Cool it’s not giving me any trouble so it must be working but I think I’m using this the wrong way.
I was thinking I could pass in whatClick here:
function loadGallery()
{
mySlideshow = new Slideshow();
mySlideshow.xmlPath = whatClick();
mySlideshow.autoLoad = false;
mySlideshow.setSize(500, 420);
mySlideshow.x = 476.5;
mySlideshow.y = 27.5;
mySlideshow.setBorder = false;
mySlideshow.preloaderType = “circular”;
mySlideshow.transitionEffect = “fade”;
}
but that gives me a different set errors. I take it that it can’t work like this. I’m trying to think of a solution of doing this with the minimum amount of code, cause I’m getting more and more lost the more it gets.
July 30th, 2008 at 6:21 pm
here is the site if you want to have a look at what I’m up to. Just be patient plz there is no preloader.
http://www.crystal-concept.com
July 30th, 2008 at 6:43 pm
This is what you need to do:
art.addEventListener(MouseEvent.CLICK, whatClick);
photo.addEventListener(MouseEvent.CLICK, whatClick);
project.addEventListener(MouseEvent.CLICK, whatClick);
//whatclick function
function whatClick(event:MouseEvent):void
{
….
}
The way to use something like
mySlideshow.xmlPath = whatClick();
is this:
function getXMLPath():String
{
if(condition1)
{
return “images1.xml”;
}
else if(condition2)
{
return “images2.xml”;
}
else if(condition3)
{
return “images3.xml”;
}
return null;
}
mySlideshow.xmlPath = getXMLPath();
But you don’t need this approach because in your project you need to listen for mouse events.
BTW, nice website :)
July 30th, 2008 at 7:20 pm
Thanx FlashOtaku, I try.
I’ll give this a spin tomorrow at work, but you will hear from me again, I can assure you.
Thanx for all the help
August 3rd, 2008 at 3:56 pm
I can’t get it to work. When I click any button since the thumbs were loaded it loads the new thumbs for a split second then reloads the previous thumbs. I know it’s something I’m not doing right but what!?
All I did was add the code you helped me with above. Where exactly do I use the whatClick function I wrote?…I don’t understand :(
August 5th, 2008 at 8:38 am
I had another idea. Can I use that if block above inside the scroller and slidshow functions to check what button was clicked and load that xml? If so…how? I tried it as it is but I get this error:
1120: Access of undefined property event.
so there must be another way of doing it.
This is what I’m after
//gallery functions
function loadGallery()
{
if (event.target == art)
{
mySlideshow.xmlPath = “images.xml”;
}
else if (event.target == photo)
{
mySlideshow.xmlPath = “images1.xml”;
}
else if (event.target == project)
{
mySlideshow.xmlPath = “images2.xml”;
}
mySlideshow = new Slideshow();
//mySlideshow.xmlPath = “images.xml”;
mySlideshow.autoLoad = false;
mySlideshow.setSize(500, 420);
mySlideshow.x = 476.5;
mySlideshow.y = 27.5;
mySlideshow.setBorder = false;
mySlideshow.preloaderType = “circular”;
mySlideshow.transitionEffect = “fade”;
}
same for the thumbLoader just differnet xml’s.
August 5th, 2008 at 4:26 pm
Hi franco,
Here’s an example http://flashotaku.com/files/gallery_ex8_as3.zip.
August 5th, 2008 at 5:52 pm
Thank you very much for your trouble, I feel like I’m pushing my luck here. The example you posted I managed to do right since you helped me with it in the previous posts and it worked well, but my movie should go as follows.
1.movie loads, just three buttons on screen (this I get right, your example loads from the start which I changed to load only when a button is clicked)
2.when button is clicked, it loads it’s own xml (at the moment it loads the xml set in the thumb and slide functions, this in turns causes the same xml to load no matter what button I click first…it works after I click different buttons)
The problem is just that it loads same xml on the first click of any of the buttons.
I hope I’m explaining myself correct here (I don’t feel like I do)
Thanx again for your time
August 6th, 2008 at 11:36 am
Here’s another example in which the components are initialized only after a button is clicked: http://flashotaku.com/files/gallery_ex9_as3.zip
August 6th, 2008 at 1:05 pm
Thank you, thank you, thank you! That is exactly what I was after.
Great stuff!
August 6th, 2008 at 3:21 pm
Glad it helps :)
August 11th, 2008 at 9:13 am
Hi FlashOtaku
Thank you again for the example, it works great except that my scroller doesn’t scroll the thumbs anymore. I didn’t change anything other than what the example showed me. Do you know what the problem could be?
August 11th, 2008 at 3:55 pm
Hi franco,
After you instantiate the scroller, add this:
myScroller.mouseMove = true;
August 11th, 2008 at 4:56 pm
Thats not working. I changed my whole approach on the project. I’m doing all of it in flash cs3 and no longer in a class file if that would make a difference.
August 11th, 2008 at 5:25 pm
Ok. Add myScroller.mouseMove = true inside the resizeScroller function. It works this way. I’ve tested it.
Writing your code in the main timeline and not using a document class wouldn’t make any difference.
August 11th, 2008 at 5:46 pm
Works like before, thank you.
August 12th, 2008 at 11:00 am
Okay so I’ve added the example from the post where you added the text loaded from the XML but I can’t get it to load the XML, must both the title and description fields in the XML have text in them for this to work?
Cause I display the title with all of the galleries and only
the description with one of them…which brings me to my other question.
How will I load the different XML files like I did with the previous stuff you helped me with. I thought of putting it in the initialize function under the whatClick but again, I don’t know the syntax for that.
August 12th, 2008 at 12:32 pm
It’s not necessary to have text in both fields.
Also, the title and description can be placed inside your current XML files, as you can see in that example. Then inside the whatClick function, each time you change the XML files you also need to parse the new XML file and populate your title and description arrays with values from that XML file.
August 14th, 2008 at 7:01 am
Hi FlashOtaku.
You must be tired of me by now but please bare with me. I have a couple of questions.
1. Is it possible to enlarge the image to its original size in the slideshow component when clicked on?
2. I get the 1009 error in the output box when I put in the XML part that is supposed to load the text. I haven’t tried the method you explained above yet because I cant get it to load as is. What am I doing wrong?
3. I ask you this question because nobody else seems to know what the problem is in other forums and you advise always works. I start a timer to delay the load of the scroller and slideshow till after the boxes are tweened in…the reason I want it like this is because I’m running this movie from a cd and not the net so there won’t be any loading of thumbs or pictures (it all happens fast) at the moment the slide and scroller loads up before the boxes are finished tweening and I got the timer to work in a sense but after the boxes tween the scroller and slide doesn’t load, it just shows the outline of them.
Hope you can make sense of this.
Thank you again – and if you need my code I will gladly mail it to, it’s a bit much to post on your page every time.
August 14th, 2008 at 12:53 pm
Hi franco,
Please email me your file at flashotaku [at] gmail [dot] com.
October 22nd, 2008 at 10:22 pm
Hi, is there a way to get the scroller to start at a random point in the list.
For example I have an xml file with 20 items, normally every time someone views the web page it would show items 1-5 so unless they scrolled they wouldnt see items 6-20.
So is it possible to get the flash file to load at random what is visible/centred on the stage so that people see something different each time?
Thanks for your help
October 23rd, 2008 at 3:51 pm
Hi,
You could only achieve that if you dynamically generate the XML file using PHP and set a random order for the nodes.
October 23rd, 2008 at 6:48 pm
Thanks, i will look into it.
Just another quick question…is it possible to set the xmlpath parameter using flashvars via Javascript on a html page?
I want to pass the scroller a different xml file from a button on my webpage and i dont know if something like
addParam(“xmlpath”, “thumbnails2.xml”);
would work. it doesnt seem to at the moment but i thought you might know how.
Many thanks
October 24th, 2008 at 8:30 am
Let me clarify what I mean
I have the following code on a webpage:
var s3 = new SWFObject(“flash/scroller.swf”,”single”,”300″,”10″,”7″);
s3.addVariable(“xmlPath”, “thumbnails2.xml”);
s3.write(“scroller”);
and I want to pass a different “xmlPath” to the flash using a text link
I have all the javascript in place to do it as i have it working on a different flash file but i want to know if this one will allow Variables to be passed to it
Thanks
October 24th, 2008 at 2:56 pm
Hi,
Here’s an example using SWFObject 2 :
http://flashotaku.com/files/gallery_ex13_as3.zip
October 24th, 2008 at 5:14 pm
Hi, thanks for that, it works great, only problem is i was using your scroller that opens a url when the thumbnail is clicked and i cant seem to work out how to add this code to the code you put in the example you sent me
Any ideas? I think it is mixing up loading the xml path and loading an xml with the urlpath array
October 26th, 2008 at 9:18 am
I’ve tried following your example to add in on-click url functionality but it doesnt seem to work with the action script that you put in on the example you posted above.
Any help would be really appreciated. Thanks
October 27th, 2008 at 2:41 pm
You need to replace
var urlRequest:URLRequest = new URLRequest(“thumbnails.xml”);
with
var urlRequest:URLRequest;
if (xmlPath != null)
{
urlRequest = new URLRequest(xmlPath);
}
else
{
urlRequest = new URLRequest(“thumbnails.xml”);
}
October 27th, 2008 at 4:30 pm
Hi FlashOtaku,
I’m really sorry but I seem to have got completely lost in all of this! Is it possible for you to post me an example which has url clicks and also allows me to tell the scroller to load a different thumbnail.xml when someone clicks on a link like the one below:
load thumbnails 2
October 28th, 2008 at 3:24 pm
Hi, sorry it looks like the link i put in there has been transformed into an actual link
I would like it to load a different xml from a link such as a href = javascript:swapXml(‘thumbnails2.xml’)
October 28th, 2008 at 5:45 pm
Hi Andrew,
Here’s a sample: http://flashotaku.com/files/gallery_ex14_as3.zip. Hope it helps.
November 2nd, 2008 at 6:00 pm
Hi FlashOtaku,
thanks for this, i’ve been playing around with it for a few days and i thought everything was fine, only problem is now it seems that when i load a new xml file it keeps the url request data from the previous xml that was loaded
I think it has something to do with the following:
if (xmlPath != null)
{
myScroller.xmlPath = xmlPath;
urlRequest = new URLRequest(“thumbnails.xml”);
}
else
{
myScroller.xmlPath = “thumbnails.xml”;
urlRequest = new URLRequest(“thumbnails.xml”);
}
if i load thumbnails2.xml it keeps the url request information from thumbnails.xml. Can’t get my head around how to fix it
November 2nd, 2008 at 11:00 pm
Hi Andrew,
You’re right, for (xmlPath != null) it should actually be
myScroller.xmlPath = xmlPath;
urlRequest = new URLRequest(xmlPath);
November 3rd, 2008 at 9:46 am
Hi, sorry I tried changing the code to that but it keeps the urlPath from the previous xml file but loads the new images.
I have simplified the xml files to:
thumbnails1.xml
thumbnails2.xml
for testing purposes but when it swaps the xml file to thumbnails2.xml the link remains http://www.1.com but the image swaps to 02.jpg
does the swapXML function called later on have to be modified to also include a swap for the URLRequest?
the code in the example you posted earlier has this:
function swapXML(newFile:String):void
{
myScroller.xmlPath = newFile;
}
ExternalInterface.addCallback(“swapXML”, swapXML);
November 3rd, 2008 at 9:48 am
sorry, the xml files are:
thumbnails1.xml
thumbnails2.xml
November 3rd, 2008 at 9:49 am
sorry, it keeps re-writing them as actual html code!
the xml files are:
thumbnails1.xml
image path = 01.jpg urlPath = www . 1 . com
thumbnails2.xml
image path = 02.jpg urlPath = www . 2 . com
November 3rd, 2008 at 6:15 pm
Hi Andrew,
I’ve looked at the full source and it seems that there were a few things that needed to be added.
See if this works: http://flashotaku.com/files/gallery_ex15_as3.zip
November 6th, 2008 at 1:17 pm
Thanks Flash Otaku, it works just perfect now, i’ll post the site when its all up and running, its exactly what i wanted. Your new site looks amazing btw. Love it.