Skip to main content
Participant
June 11, 2008
Question

Actionscript help on semi-advance flash

  • June 11, 2008
  • 1 reply
  • 667 views
So I'm trying to create a flat carousel similar to the one located here http://www.square-enix.com/na/index_f2.html
(as a side note before reading the 2nd half, my trouble is with the thumbnail loop buttons)

I have created all the graphic elements, now I'm in the planning stage of the actionscript, and this is where I'm hitting some trouble, so if I could barrow some actionscript pro's mind that would be awesome.

My thought process is to create a movie clip and have it be replaced with images imported through an XML file (for easy updating). After this part I run into trouble, I'm planning on taking the MC that got replaced and duplicating it and running the MC's side by side, and when one goes too far to the left or right move it to the other end of the other MC, this way I create an infinite loop.


My Questions:
so like how would you make one of the MC's reposition it's self on the X axis to the end of the other movie clip once it has moved far enough left or right ? (also what is the method you would use to tell flash the limit that the MC is far enough left or right and it should reset it's self?)

How would you make each thumbnail button change the image on the main stage upon clicking the thumbnail button when all the images are imported through the xml document?

Thank you for help and time spent reading this.

if you have any questions, please ask.

thanks once again.

-Mark
This topic has been closed for replies.

1 reply

robdillon
Participating Frequently
June 13, 2008
I make two displayobjects. They are identical and contain each of the thumbnail images that I want to show. When I add the first display object, it is set at the left edge of the stage, I give it a y position so that it isn't at the top of the stage. Then I position the second object at the right end of the first object. The x position is the width of the first object. The y position is the same as the first. When the objects are moving across the stage, the second follows the first. If the objects are moving to the left, then I reposition the first to the right of the second when it's x position is less than the negative value of the width of the object. When the objects are moving to the right, I reposition the second object to the left of the first when the second's x position is greater then it's width.

I make a third display object that is used to show the large images. During the construction of each of these display objects, I provide a name property for each image as it is added. Then I can use the event.currentTarget.name property to find out which image was click on. I can then find the image in the third display object to show as it has the same name.

This code that I've attached does more than what you describe, but you should be able to scrape out the parts that you need. Look at the functions onEF and bigMe. They contain the code that I mentioned above.
Participant
June 16, 2008
Rob,

First of all I would like to greatly thank you for all you have done for me. It has been so useful and such a learning experience getting to go through your personal code. and manipulating it to my personal flash. Thank you so much!

However, I'm reaching some trouble when I try to import my XML file, or something is just missing.

so here is the break down:

in my main .fla file I have this actionscript to import your .as file (with modifications made to the name and package)

var Carousel:carousel = new carousel();
trace(Carousel);

now that seems to import into my FLA just fine, the trace tells me that [object carousel] which I assume that means the object has loaded into the FLA.

So anyway there is nothing on my stage in the main FLA, which I assume is because the XML is not getting loaded properly into the flash/actionscript.

My XML (minus all the images but one):

<icons>

<icon image="icon1.jpg" />

</icons>

so this is the basic of my XML, when I import the xml into a more simpler file the jpgs work just fine.

now I thoroughly went through your script examining every functions and var and I'm able to understand majority of it however parts of the import section is what confuses me, so if you could help me understand the script more that would be amazing.


(the line numbers are probably off a little because I deleted a couple unnecessary variables for my flash)

in line 57: urlLoader.addEventListener("complete", loaded);
why do you have "complete" instead of Event.COMPLETE... is there a difference?

in line 81 & 82: var count1:uint = source.indexOf("/") + 1;
var count2:uint = source.indexOf(".");
please explain what "/" and "." means... do I replace it with location of the nodes in my xml?


so yeah this is the gist of it, if you could help me figure out how to import my XML properly that would be great, or if you do not have the time do that maybe you could let me check out your XML, piece it all together and figure out the difference of your working copy and my unworking copy.

Once again Thank you so MUCH! for taking your time in helping me out, I hope things are going well for ya.

-Mark
robdillon
Participating Frequently
June 17, 2008
quote:

in line 57: urlLoader.addEventListener("complete", loaded);


Yes, "complete" is functionally equivalent to event.COMPLETE.

quote:

in line 81 & 82: var count1:uint = source.indexOf("/") + 1;
... etc.

What this is doing is grabbing a section of the file name to use a name for the imported item. In my movie, my .jpg files were in a folder and so the path to the images was "photos/file1.jpg". To get the word "file" from that string, I needed to find the character number of the "/" and the "." and then grab the characters in between the two. If your images are not in a folder, then you can just set the value of count1 to 0.

In the function importImages(), if you have no other nodes in your XML, then be sure to remove the section in that function about the tooltip node.

Let me know if you need anything else to get it working for you.