Connecting Tech Pros Worldwide Help | Site Map

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

anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#1: Aug 4 '09
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.  
anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#2: Aug 6 '09

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


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
Reply