Welcome, Guest
  • Author Topic: Loading data into Flash from database  (Read 4434 times)

    spoider

    • Server what's that
    • *
    • Posts: 10
      • View Profile
    Loading data into Flash from database
    « on: 02/29/08, 14:42 »
    Hi all. This is my first post.
    I need help with two things:

    1: the tutorial loading data into flash from php works fine. But what i need is that the data shows from a variable.

    lets say that i have 3 links in a php file:

    <a href="anastasio.php?foto=an1.jpg">foto1</a>
    <a href="anastasio.php?foto=an2.jpg">foto2</a>
    <a href="anastasio.php?foto=an3.jpg">foto3</a>

    How do i pass the variable an1.jpg to the swf from the link?

    2: since i´m gonna use it to show images how do i also make a preloader to the image loaded?

    can i use this code? or does anybody have a better preloader?


    function startLoading(whichImage) {
       loadMovie(whichImage, "imageLoader");
       _root.onEnterFrame = function() {
          infoLoaded = imageLoader.getBytesLoaded();
          infoTotal = imageLoader.getBytesTotal();
          percentage = Math.floor(infoLoaded/infoTotal*100);
          infoField.text = percentage+"%";
          if (percentage>=100) {
             delete this.onEnterFrame;
             infoField._visible = false;
          }
       };
    }

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: Loading data into Flash from database
    « Reply #1 on: 02/29/08, 20:53 »
    Parse strings rely on the constant of the expression, so if all links will looks similar, some simple way of getting the portion could be

    $a = '<a href="anastasio.php?foto=an1.jpg">foto1</a>';
    $b = explode("=", $a);
    $c = explode("\"", $b[2]);
    echo $c[0];

    But this should be combined in a parse function. If input is not so regular, probably a regular expression could help.
    Preloader code is fine, but if you want to create containers on the fly, probably you want to create the container using createEmptyMovieClip instead of using always "imageLoader", since each image will replace the previous

    Jorge

    spoider

    • Server what's that
    • *
    • Posts: 10
      • View Profile
    Re: Loading data into Flash from database
    « Reply #2 on: 03/01/08, 03:00 »
    well, i´m gonna have 100´s of images, i just want to load the images more dynamic from a url with variables.

    i have a php file that gets the variables from the database, when i press the link, the variable is sent to the swf and the image and description shows. (thats my idea)

    The tutorial  just load all the images from the database, and not on specific image.

    here is another tutorial i found that mabe help:

    how to send the variables:

    <a href="anastasio.php?lang=an1.jpg">image 1</a>
    <a href="anastasio.php?lang=an2.jpg">image 2</a> and so on...

    the anastasio.php:

    <?php
    $lang = $_GET['lang'];
    ?>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0" width="550" height="400">
      <param name="movie" value="lv_10.swf?<?php echo ("lang=$lang"); ?>" />
      <param name="quality" value="high" />
      <embed src="lv_10.swf?<?php echo ("lang=$lang"); ?>" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400"></embed>
    </object>

    And finally the swf:

    this.createTextField("t_txt", 1, 100, 100, 1, 1);
    t_txt.autoSize = true;
    t_txt.text = "the chosen language is:\n" + lang;


    Any idea how to get all together?

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: Loading data into Flash from database
    « Reply #3 on: 03/01/08, 06:24 »
    I can't get your workflow. You load url's ( in Flash?, why url's and not just images), then when pressing the link, you show the image and a detail (more text?) You load all the data at once, you want to load daa in chunks, on demand?

    Jorge


    spoider

    • Server what's that
    • *
    • Posts: 10
      • View Profile
    Re: Loading data into Flash from database
    « Reply #4 on: 03/01/08, 07:24 »
    Ok, i´m gonna explain it as good as possible!
    I´m ready with my gallery. It´s done in php and mysql database. Since the images are in high resolution, i would like to have a preloader before they show in the browser. (they are quite big)

    My idea is that the image and and a short description shows in the swf.

    So, i have a menu with the categories, i choose one of the categories, and the thumbs appear in a php file.
    as i have it now, it show the image in a phpfile, it works, but it takes a while to load the image... that´s qhy i want to show it on a swf with a preloader.

    So the next step is that when i choose a thumb from the category, it opens in the swf. it preloads first shows the image and a description. thats that simple.

    the only thing left is the flashpart :)

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: Loading data into Flash from database
    « Reply #5 on: 03/01/08, 13:39 »
    So you have your gallery with thumbs and use flash just to open the big image and show a preloader. Then use flashvars to pass the name of the image (just the image name, not the link, is not neccesary), probably using some Javascript to open the window.  http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_16417&sliceId=1. The preload code you posted is fine

    Jorge

    spoider

    • Server what's that
    • *
    • Posts: 10
      • View Profile
    Re: Loading data into Flash from database
    « Reply #6 on: 03/02/08, 11:49 »
    Hi again.
    I´m almost there. This is acutually my first flash project, so i´m a newbie here.

    Here is what i´ve done:

    I send the the variables to a phpfile. like this:
    <a href="file.php?image=an1.jpg&description=my first image">Image 32</a>

    The file.php:

    <?php
    $image = $_GET['image'];
    $description = $_GET['description'];
    ?>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0" width="550" height="400">
      <param name="movie" value="file.swf?<?php echo ("image=$image&description=$description"); ?>" />
      <param name="quality" value="high" />
      <embed src="file.swf?<?php echo ("image=$image&description=$description"); ?>" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400"></embed>
    </object>

    and the code in flash:

       infoField._visible = true;
       startLoading (+ image);

    function startLoading(whichImage) {
       loadMovie(whichImage, "imageLoader");
       _root.onEnterFrame = function() {
          infoLoaded = imageLoader.getBytesLoaded();
          infoTotal = imageLoader.getBytesTotal();
          percentage = Math.floor(infoLoaded/infoTotal*100);
          infoField.text = percentage+"%";
          if (percentage>=100) {
             delete this.onEnterFrame;
             infoField._visible = false;
          }
       };
    }

    Comments.text = "text here:\n" + description;


    This actually works for mee. I get a image and description of the image depending on wich image i choose i´m my php gallery. However yhe preloader doesn´t work. Any idea why? what´s missing in the preloader?

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: Loading data into Flash from database
    « Reply #7 on: 03/02/08, 12:03 »
    For the preloader to work you should:

    1. Call it correctly:

    startLoading (image);

    2. Have a container (empty MC at 0,0 position) with instance name "imageLoader"
    3. Have a dynamic textfield somewhere with instance name "infoField" to show the percentage

    Jorge

    spoider

    • Server what's that
    • *
    • Posts: 10
      • View Profile
    Re: Loading data into Flash from database
    « Reply #8 on: 03/02/08, 14:57 »
    the thing is, if i ad a button with a function it will work
    ex:

    imgbtn1.onRelease = function() {
       infoField._visible = true;
       startLoading(image);
    };

    but how to remove the buttonfunction and still making it work?
    « Last Edit: 03/02/08, 15:09 by spoider »

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: Loading data into Flash from database
    « Reply #9 on: 03/02/08, 21:32 »
    Just leave

      infoField._visible = true;
       startLoading(image);

    The button is not more needed

    Jorge

    spoider

    • Server what's that
    • *
    • Posts: 10
      • View Profile
    Re: Loading data into Flash from database
    « Reply #10 on: 03/02/08, 23:42 »
    Solved!

    If i only use the code below nothing happens:

    infoField._visible = true;
       startLoading(image);


    But when changing to this:

    _root.onEnterFrame = function() {
       infoField._visible = true;
       startLoading(image);
    };

    works just fine....

    Time to finish it all now.
    Thank you Jorge solis
    « Last Edit: 03/02/08, 23:55 by spoider »