473,416 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

actionscript to load captions from array to dynamic text when thumb is clicked

anfetienne
424 256MB
i have this code below that i made....it loads vars from txt file splits it then puts it into an array....once in an array it the brings the pics in from the array to create thumbnails and a larger image. my problem is i have captions to go with it and when i try to load the captions nothing happens or can be seen to be happening.

i dont know where i am going wrong as i have no output or compiled errors

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. var locVar = new Array();
  4. locVar = imgLoc.split(",");
  5. trace ( locVar );
  6.  
  7. var tmbVar = new Array();
  8. tmbVar = tmbLoc.split(",");
  9. trace ( tmbVar );
  10.  
  11. var capVar = new Array();
  12. capVar = imgCap.split(",");
  13. trace ( capVar );
  14.  
  15. var NPICS:Number = locVar.length;    // number of pictures to load
  16. var PICX:Number = 32.8;               // x loc of big picture
  17. var PICY:Number = 24.9;               // y loc
  18. var THUMBHOLDERX:Number = 50;        // x location of thumbnail holder movieclip
  19. var THUMBHOLDERY:Number = 457;      // y location
  20. var THUMBW:Number = 100;             // width of each thumbnail
  21. var THUMBH:Number = 75;             // height
  22. var MARGIN:Number = 10;             // margin between thumbnails
  23. var TOTALBYTES:Number = 212000;     // approx sum of bytes in all jpgs (x 2)
  24. var MAXPIXELS:Number = 12;          // max number of pixels to move slider per frame
  25.  
  26. // mask definition; mask is assumed to cover some part of the thumbnail slider (here the numbers
  27. // were chosen so that there are margins between the mask and the right and left edges of the movie
  28. // (which is 420 x 290), and enough space above and below the thumbs to show them when they 'grow'
  29. // on mouseover
  30. var MASKX:Number = 0;                // start x location of mask
  31. var MASKW:Number = 600;                // mask width
  32. var MASKY:Number = 447.9;                // start y location of mask
  33. var MASKH:Number = 92;                // mask height
  34.  
  35. var totalloaded:Number = 0;         // running tally of bytes loaded from all pics
  36.  
  37. // index into pictures array, used for loading
  38. var ipic:Number;
  39.  
  40. // set up loader, an instance of MovieClipLoader
  41. var loader:MovieClipLoader = new MovieClipLoader();
  42.  
  43. // use the main timeline to listen to and respond to loader's broadcast events
  44. loader.addListener(this);
  45.  
  46. // function to move thumbnail slider ("this" = thumbs_mc)
  47.  
  48. function sliderControl() {
  49.    var w:Number = this._width/2;
  50.    var hw:Number = mask_mc._width/2;
  51.    var npixels:Number;
  52.    // only do when mouse over slider mask
  53.    if (_ymouse > mask_mc._y && _ymouse < mask_mc._y + mask_mc._height) {
  54.       // mouse over left half of slider:
  55.       if (_xmouse > mask_mc._x && _xmouse < mask_mc._x + hw) {
  56.          npixels = (hw - _xmouse) / hw * MAXPIXELS;
  57.          this._x += npixels;
  58.          if (this._x >= 0) this._x = this._x - w;
  59.       // mouse over right half of slider:
  60.       } else if (_xmouse > mask_mc._x + hw && _xmouse < mask_mc._x + mask_mc._width) {
  61.          npixels = (_xmouse - hw) / hw * MAXPIXELS;
  62.          this._x -= npixels;
  63.          if (this._x <= -w) this._x = this._x + w;
  64.       }
  65.    }
  66. }
  67.  
  68. // thumbnail click (onrelease) handler
  69.  
  70. function openPic() {
  71.    pic_mc.loadMovie(locVar[this.i]);
  72. }
  73.  
  74. function brightON(){
  75.     this._alpha = 300;
  76. }
  77. function brightOFF(){
  78.     this._alpha = 30;
  79. }
  80. function captionTXT(){
  81.     _root.cap_txt = capVar;
  82. }
  83.  
  84. // assign event handlers (called when all jpgs are loaded)
  85.  
  86. function setupHandlers() {
  87.    pct_txt.removeTextField();        // don't need loading indicator any more
  88.    thumbs_mc.onEnterFrame = sliderControl;
  89.    for (var i:Number = 0; i < NPICS*2; i++) {
  90.       thumbs_mc["mc"+i].onRollOver = brightON;
  91.       thumbs_mc["mc"+i].onRollOut = brightOFF;
  92.       thumbs_mc["mc"+i].onMouseDown = captionTXT;
  93.       thumbs_mc["mc"+i].onRelease = openPic;
  94.    }
  95. }
  96.  
  97. // listener function for broadcast 'done' message (for each pic)
  98. // onLoadInit gets executed when the movieclip has been loaded into _mc AND 
  99. //   its width and height data are available.
  100. //   (_mc = the movieclip being loaded into)
  101. // this routine sets the size and position of each thumbnail clip as its jpg
  102. //   is loaded and starts the next one loading.  When all have been loaded, 
  103. //   a random picture is loaded into pic_mc and setupHandlers is called to 
  104. //   assign handlers to each thumbnail movieclip
  105.  
  106. function onLoadInit(_mc:MovieClip) {
  107.    // this gets done when the jpg is completely loaded:
  108.    _mc._width = THUMBW;
  109.    _mc._height = THUMBH;
  110.    _mc._alpha = 30;        // for image clarity
  111.    // give the movieclip a property to remind it who it is
  112.    // (used by openPic to know which big picture to open)
  113.    _mc.i = (ipic >= NPICS ? ipic-NPICS : ipic);
  114.  
  115.    // add picture size to totalloaded variable
  116.    totalloaded += loader.getProgress(_mc).bytesTotal;
  117.  
  118.    // now load the next one (if there are more) or set up handlers if done
  119.    ipic++;
  120.    if (ipic == NPICS * 2) {
  121.       // start with a random photo displayed when all thumbs loaded
  122.       pic_mc.loadMovie(locVar[Math.floor(Math.random()*NPICS)]);
  123.       setupHandlers();
  124.    } else if (ipic >= NPICS) {
  125.       // load jpg into duplicate thumbnail (will already be cached)
  126.       loader.loadClip(tmbVar[ipic-NPICS],  thumbs_mc["mc"+ipic]);
  127.    } else {
  128.       // load jpg into thumbnail
  129.       loader.loadClip(tmbVar[ipic],  thumbs_mc["mc"+ipic]);
  130.    }
  131. }
  132.  
  133. // listener function to handle broadcast progress messages
  134. // make pct_txt show cumulative loading progress
  135.  
  136. function onLoadProgress(_mc:MovieClip, loaded:Number) {
  137.    var loadedsofar:Number = totalloaded + loaded;    
  138.    pct_txt.text = Math.floor(loadedsofar / TOTALBYTES * 100) + "%";
  139. }
  140.  
  141. function init() {
  142.    // create holder for pictures
  143.    createEmptyMovieClip("pic_mc", 1);
  144.    pic_mc._x = PICX;
  145.    pic_mc._y = PICY;
  146.  
  147.    // create (and draw) holder for thumbnails 
  148.    createEmptyMovieClip("thumbs_mc", 2);
  149.    thumbs_mc.beginFill(0, 100);    // black
  150.    thumbs_mc.moveTo(0, 0);
  151.       thumbs_mc.lineTo(2 * (MARGIN + THUMBW) * NPICS, 0);
  152.    thumbs_mc.lineTo(2 * (MARGIN + THUMBW) * NPICS, THUMBH);
  153.    thumbs_mc.lineTo(0, THUMBH);
  154.    thumbs_mc.endFill();
  155.    // drawing the thumb holder at 0, 0 and then moving it makes its reg point = upper left
  156.    thumbs_mc._x = THUMBHOLDERX;
  157.    thumbs_mc._y = THUMBHOLDERY;
  158.  
  159.    // create, draw and enable mask over thumbs (could use different variables to define mask
  160.    // if desired)
  161.    createEmptyMovieClip("mask_mc", 3);
  162.    mask_mc.beginFill(0x0000cc, 100);
  163.    mask_mc.moveTo(0, 0);
  164.    mask_mc.lineTo(MASKW, 0);
  165.    mask_mc.lineTo(MASKW, MASKH);
  166.    mask_mc.lineTo(0, MASKH);
  167.    mask_mc.endFill();
  168.    mask_mc._x = MASKX;
  169.    mask_mc._y = MASKY;
  170.    thumbs_mc.setMask(mask_mc);
  171.  
  172.    // create loading textfield indicator
  173.    createTextField("pct_txt", 4, 200, 100, 40, 100);
  174.    var tf:TextFormat = new TextFormat();
  175.    tf.align = "center";
  176.    tf.size = 12;
  177.    tf.font = "Verdana";
  178.    tf.color = 0xFFFF00;
  179.    pct_txt.setNewTextFormat(tf);
  180.  
  181.    // create loading textfield indicator
  182.    createTextField("cap_txt", 0, 400, 200, 40, 100);
  183.    var cf:TextFormat = new TextFormat();
  184.    cf.align = "center";
  185.    cf.size = 12;
  186.    cf.font = "Verdana";
  187.    cf.color = 0xFFFF00;
  188.    cap_txt.setNewTextFormat(cf);
  189.  
  190.    // make empty movieclips in thumbs_mc for each pic to go into
  191.    // make double the number so the slider can move continuously and show content
  192.    for (var i:Number = 0; i < NPICS * 2; i++) {
  193.       var mc:MovieClip = thumbs_mc.createEmptyMovieClip("mc"+i, i+1);
  194.       mc._x = i*(MARGIN + THUMBW);
  195.       mc._y = 0;
  196.    }
  197.  
  198.    // set the pointer to the first jpg in the array picnames
  199.    ipic = 0;
  200.    // start loading jpgs (ipic is initialized to 0)
  201.    loader.loadClip(locVar[ipic], thumbs_mc["mc"+ipic]);
  202. }
  203.  
  204. init();
  205. stop();
  206.  
Aug 4 '09 #1
1 3618
anfetienne
424 256MB
ok i've solved my problem to get captions to be shown but im having a problem with looping.....

is anybody able to help me with as 2? i dont feel like writing a long post if no-one is actually going to reply so if anyone can help ill post after you replied......thanks in advance, its much appreciated
Aug 6 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: CB US 77 | last post by:
I use a piece of javascript to create a photo gallery slideshow. The slideshow part works great, but I would like to add captions to each picture. If you want to see the html, send me an email to...
17
by: Stian Lund | last post by:
Hello, I've been struggling with this problem for a while now, so I though I'd get some input from anyone more skilled with CSS than I am. I'm actually trying to accomplish two things with this:...
0
by: Eric Diana | last post by:
Hello, Im trying to create a dynamic array of textboxes from an array returned by a web service. THe web service returns a list of fields that I need to place on a dynamically created web page....
3
by: paolazi | last post by:
Hello I have a problem: I have a database(mysql) with the following fields: test, descr, title I want to display them into a flash file. Now my php file called list.php (which collect the...
0
by: Dionysusmtl | last post by:
I'm working on a flash portfolio that loads examples of our work (jpgs) into a movie. For example, it started off using an xml list to display certain images but I found it necessary to draw info...
0
by: gabrielk43 | last post by:
Hi I am new to Flex and I use Flex Builder 2 to make a web service client. So I have a web service in .NET(c#) with a simple web method that returns a string(no arguments). It works, I tested it...
0
by: shaqa | last post by:
I try to do this but i cannot. i creat two layers with actionscript seperated as slideshow need to be,,and i try to put in one rectangle all of my images but cannot put in work,it doesnt load when i...
2
by: saijin | last post by:
I've been trying to implement simple lines of XML into my flash file created with ActionScript 3.0, but things seem not to be working. All I want to do is to load an external XML file (data.xml),...
4
nathj
by: nathj | last post by:
Hi, Well the title of the thread is the question. I have tried searching for this and after several days of getting nowhere with it I decided I would ask. So here's the deal. I am using Flash...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.