dcsimg
A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: How to load dynamic text according to dynamic image?

  1. #1
    registered misuser
    Join Date
    Feb 2004
    Location
    Io, Vicinity of Jupiter
    Posts
    157

    How to load dynamic text according to dynamic image?

    Hello all,

    I want to make this artist portfolio (ie: a slide show) and I have found a tutorial that showed me how to dynamically load images in an empty movie clip.

    Now, I'd like to attach a description for each images and I'd like to keep it dynamic. So, I imagine a folder with one text per image, having a name can can be incremented or decremented (description1.txt, description2.txt, and so on)

    and I guess it's a matter of having a recognition of which image we're on in order to load the corresponding text...

    Also, I was wondering, can I add html tag in the txt file in order to have some sort of formatting to the output text?

    Where do I start?

    Thanks

    p.

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    You can create a function that loads
    both the text
    and the image
    depending on a variable i.

    For example:
    code:

    function myFunction(i)
    {
    // load image i:
    my_mc.loadMovie("imagem" + i + ".jpg");
    // load text i:
    var my_lv = new LoadVars();
    my_lv.onLoad = function()
    {
    // show text i
    };
    my_lv.load("text" + i + ".txt");
    }



    Here's a post that shows how to load html text.

  3. #3
    registered misuser
    Join Date
    Feb 2004
    Location
    Io, Vicinity of Jupiter
    Posts
    157
    Thanks nunomira,

    I see what you're saying, but the thing is that I already have a bit of code written that it took me quite a while to understand and get working. And I'm almost terrified at the idea of starting from scratch again.

    here's the code I have, maybe it's just a matter of one more line somewhere in there!!!

    (square = empty MC into which images load)
    (mypic = variable for the images)

    Code:
    square._alpha=0;
    mypic=1;
    
    _root.onEnterFrame = function()
    {
    	if (square._alpha <10)
    	{
    	loadMovie("images/image"+mypic+".jpg","square")
    	fadeOut=false;
    	fadeIn=true;
    	}
    	
    	if (square._alpha > 10 && fadeOut)
    	{
    	square._alpha -= 10;
    	}
    	
    	if (square._alpha < 100 && fadeIn && !fadeOut)
    	{
    	square._alpha += 10;
    	}
    	else
    	{
    	fadeIn=false;
    	}
    }
    Maybe in the "loadMovie" block, some line(s) could be added...

    I know I sound like this unfortunate lost soul, but it's a bit true, since objects got in there... It seems such a long way from scripting...

    thanks for quiding a lost soul to salvation

    p.

  4. #4
    registered misuser
    Join Date
    Feb 2004
    Location
    Io, Vicinity of Jupiter
    Posts
    157
    hey, I was thinking...

    I'm using an empty MC for the images, it makes sense to use another for the text??? Does it?

    humm, I'm trying but it ain't easy!

  5. #5
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    You can have another movie clip with the text field, or you can have the text filed on the same timeline as the empty movie clip you load the pictures into.

  6. #6
    registered misuser
    Join Date
    Feb 2004
    Location
    Io, Vicinity of Jupiter
    Posts
    157
    yes I see. But I'm still trying to figure out how to create the object that will recognize which image is loaded and that will load the right text.

    Do I use "loadMovie" to load text as well or is there another better function? I'm sorry, I don't understand much of your example... I'm sure there are some elements in there that I must use, but I have a real hard time to figure out what is what and what does what...

    any pointers (maybe some keywords on which I could search)?

    thanks
    Last edited by zap danger; 09-15-2005 at 11:13 AM. Reason: new idea

  7. #7
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    Here's a very simple example that loads the previous and the next image and text.

    This is a valid way to do it, but once/if you get/are familiar with XML, xml would be a better way to handle what you want to do.
    Attached Files Attached Files

  8. #8
    registered misuser
    Join Date
    Feb 2004
    Location
    Io, Vicinity of Jupiter
    Posts
    157
    thanks a lot Nunomira,

    I think I'll be able to understand this and adapt it to my project. I don't know if I'll have to forget about the fade in and fade out, but it's not that important.

    Thanks again

    p.

  9. #9
    registered misuser
    Join Date
    Feb 2004
    Location
    Io, Vicinity of Jupiter
    Posts
    157

    So far so good...

    Hey Nunomira,

    I was able to make something good out of your example. Thanks.

    I would like to add a little feature, and I wonder if you could help me just a bit more. I want to make the «next» button jump to slide 1 when the user is on the last slide and the other way around when the user is on slide 1 (go to the last slide when clicking «previous»)

    I know this would have to be done in the button object, and I have a little idea how, but I feel I your help would get me on the right track right away.

    Thanks a lot

    p.

    ps. if you want to see what I've done :
    http://www.sourcecreation.com/slide_show/v2/show_v2.swf

  10. #10
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    code:

    next_btn.onRelease = function()
    {
    if (i < total)
    {
    myFunction(++i);
    }
    else
    {
    i = 1;
    myFunction(i);
    }
    };
    //
    previous_btn.onRelease = function()
    {
    if (i > 1)
    {
    myFunction(--i);
    }
    else
    {
    i = total;
    myFunction(i);
    }
    };


  11. #11
    registered misuser
    Join Date
    Feb 2004
    Location
    Io, Vicinity of Jupiter
    Posts
    157
    ah, yes of course the condition!!!
    thanks again, that did it.

    Only I have one more question, if you don't mind. I noticed at the begining, you define the function : myFunction(i). I understood (hopefuly right) that this function is what make the slide go forth or back. But I don't quite understand how it works. Also I wonder if the (i) refers to the variable -i- that was set. And finaly, I was wondering why this function is called back in the btn object, especially in the else statement :
    Code:
    else
    
    	{
    
    		i = total;
    
    		myFunction(i);
    
    	}
    isn't just - i = total; - enough to make it go there or is it in fact the myfunction(i); that makes it go there??? I mean without it, it would only set -i - equal to the total variable and stop (do nothing more)...

    Do I get this right?

    thanks again

    p.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center