473,748 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

anfetienne
424 Contributor
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 3645
anfetienne
424 Contributor
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......th anks 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
2734
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 usb15@cox.net. Any help would be great.
17
2269
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: 1. Create a floated image with text around, with a caption centered underneath. Image size can be varied but the caption needs to have a fixed size to make it break correctly I think. I also need the image to resize automatically when the...
0
368
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. The problem I am having is when the button event is clicked, the text typed in the textbox doesn't get saved with the textbox. I might be way off base with even trying this. If anyone could give me some idea on what is going wrong or another...
3
8631
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 information from my database) is the following: <?php include_once '../library/config.php'; include_once '../library/opendb.php'; $query =mysql_query("SELECT * FROM `$table` ORDER BY(`title`DESC ");
0
2135
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 from the database and pass some variables in the querystring to change the source of the images in the movie depending on which client is clicked. Here is the problem. I have tweaked the code and it should work fine - and sometimes it does. ...
0
2874
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 using firefox. I have managed to consume the service in Flex by using MXML like this: <mx:WebService id="wsTestWebService" wsdl="http://localhost:3521/AjaxControlToolkitWebSite2/TestFlexService.asmx?wsdl"showBusyCursor="true"...
0
1941
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 go to my choosen page. Below is the script,please any one tell me how to put all of my images to one rectangle which later i can resize it,and load the image slideshow when i open choosen page. script: layer proto: MovieClip.prototype.alpha =...
2
7358
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), and output the content which are inside the <project text="content to show"></project> tags into a scripted text field. Here are what I've been doing so far: var txtFldPassage:TextField = new TextField(); txtFldPassage.multiline =...
4
7358
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 8, I have a movie that reads information from an XML file. The trick is that depending on a selection on my web page I want the move to read a different XML file. This sounds simple enough right? I thought so, pass the variables over to the...
0
8995
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.