Welcome, Guest
  • Author Topic: LoadVars to load image data from database  (Read 5415 times)

    jhoward

    • Server what's that
    • *
    • Posts: 11
      • View Profile
    LoadVars to load image data from database
    « on: 03/08/10, 16:25 »
    Hello good people, this is my first attempt at loading data from a DB into Flash. I have successfully loaded text to two dynamic text boxes and am happy. My issue is I am on week two of trying to load an image. I have read through so many tutorials I am not going to bother showing you what I am trying to do with the iamge, I need a professionals input here for my problem.

    Below is what I have in the first frame where I dropped my movieclip.
    I then have my three dynamic text boxes in this movieclip instance, each in their own layer. Each has a variable and instance name of (VarStrTitle, VarStrSubTitle, and VarPhoto)  accordingly and all have "single line" and "render as HTML" selected.

    Code: [Select]
    onClipEvent(load)
    {
    myData = new LoadVars()
                   myData.load("flash.aspx?fid=1")
                   myData.onLoad = function(success){
                        if(success){
                             VarStrTitle.html=true;
                                    VarStrTitle.htmlText = this.VarStrTitle   
      VarStrSubTitle.html=true;
      VarStrSubTitle.htmlText = this.VarStrSubTitle  
      VarPhoto.html=true;
      VarPhoto.htmlText = this.VarPhoto
          }
          else trace ("Error loading data")
        }
    }

    The string I am passing back to my .swf from my aspx is: VarStrTitle=Savor+Specials+from+Charles+St+Restaurants&VarStrSubTitle=Downtown+Dining+Promotions+Will+Leave+You+Hungry+for+More&VarPhoto=safetyescortphoto

    My results appear as:
    VarStrTitle loads - Savor Specials from Charles St Restaurants
    VarStrSubTitle loads - Downtown Dining Promotions Will Leave You Hungry for More
    VarPhoto loads - safetyescortphoto.jpg

    Where do I go from here to make that image name (safetyescortphoto.jpg) display as an image in my flash?

    Many thanks in advance
    j

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: LoadVars to load image data from database
    « Reply #1 on: 03/08/10, 21:22 »
    after you are loading it into a html text field, you can do:
    Code: [Select]
    VarPhoto.htmlText="<img src='" + this.VarStrTitle +"'>";

    but you could use a movieclip as well:

    Code: [Select]
    yourMovieclip.loadMovie(this.VarStrTitle);

    After you are posting in the MX2004 section, I suppose you are using AS2
    happy flashing
    8)
    Ronald

    jhoward

    • Server what's that
    • *
    • Posts: 11
      • View Profile
    Re: LoadVars to load image data from database
    « Reply #2 on: 03/09/10, 09:14 »
    Ronald, thanks so much for the very fast reply!

    Yes, I am using AS2.

    I added your LoadMovie code to my original code block so that it appears as below.
    For the Dynamic text area that contains that LoadMovie code I now get: "_level0.instance6.VarPhoto"

    Just to clarify where I am placing all of my AS code. I am at scene1, and click on the MovieClip1 (that contains my 3 dynamic text fields) that I have inserted in the first keyframe.
    That is where I have the below AS code.

    Code: [Select]
    onClipEvent(load)
    {
    myData = new LoadVars()
        myData.load("flash.aspx?fid=1")
        myData.onLoad = function(success){
          if(success){
            VarStrTitle.html=true;
              VarStrTitle.htmlText = this.VarStrTitle    
     VarStrSubTitle.html=true;
     VarStrSubTitle.htmlText = this.VarStrSubTitle  
     VarPhoto.html=true;
                                      VarPhoto.htmlText="<img src='" + this.VarPhoto +"'>";
     MovieClip1.loadMovie(this.VarPhoto);
          }
     else trace ("Error loading data")
        }
    }
    « Last Edit: 03/09/10, 09:24 by jhoward »

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: LoadVars to load image data from database
    « Reply #3 on: 03/09/10, 10:45 »
    you misunderstood.

    either image tag inside of the textfield, or a loadMovie at an empty movieClip, or, as 3rd approach, insert a loader component, and assign the picture path to the source attribute ;)

    You see, there ar many ways to rome ;)
    happy flashing
    8)
    Ronald

    jhoward

    • Server what's that
    • *
    • Posts: 11
      • View Profile
    Re: LoadVars to load image data from database
    « Reply #4 on: 03/09/10, 16:05 »
    Awsome!!!!!  loader component!!!! yeah!!
    Now that you opened my eyes I have allot more to learn about components I guess, but this worked perfectly.

    I guess my next hurdles will be with positioning of the image, when best to load images for performance since I will be rotating through 5 or 6 photos....Then I plan to feed this monster with web services....of course I just noticed the WebServiceConnector Component....ohhh boy!!!

    Thanks so much for your help.

    J

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: LoadVars to load image data from database
    « Reply #5 on: 03/10/10, 02:40 »
    you position the component with the x and y attributes (AS2 it is _x and _y).
    You can have more than one loader component, some beeing set visible=false ;)
    Or set alpha=0 to make it completely transparent.

    This way you can make new fotos fade in, by changing the alpha states.
    « Last Edit: 03/10/10, 02:42 by Ronald Wernecke »
    happy flashing
    8)
    Ronald

    jhoward

    • Server what's that
    • *
    • Posts: 11
      • View Profile
    Re: LoadVars to load image data from database
    « Reply #6 on: 03/12/10, 15:30 »
    Hello again Ronald, all your feedback is working perfectly.

    I have another "hopefully last" issue I am dealing with.

    I have the below code loading in the first frame of my movie in a movieclip1, which gives me values from an aspx page fed from a DB.  (This works great for my dynamic text)
    Code: [Select]
    onClipEvent(load)
    {
    myData = new LoadVars()
        myData.load("flash/flash.aspx?fid=1")
        myData.onLoad = function(success){
          if(success){
              VarStrTitle.html=true;
              VarStrTitle.htmlText = this.VarStrTitle   
      VarStrSubTitle.html=true;
      VarStrSubTitle.htmlText = this.VarStrSubTitle
      VarLink.html=true;
      VarLink.htmlText = this.VarLink
      }
      else trace ("Error loading data")
        }
    }
    I now need to add a button (i guess) that's GetURL link will be a value (VarLink) that I can also load in that first frame as well. I didnt want to have to call to the aspx page again just to get this one value since I am already doing that in my first frame like I said.

    How can I use that loaded value from the first frame of my movie and reference it in my button getURL . I can put that button in the same layer and frame as the movieclip1, but on click I get undefined.


    Here is what I was trying in my button:

    Code: [Select]
    on (release) {
      getURL(this.VarLink,"_blank");
    }


    Many thanks again.

    J

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: LoadVars to load image data from database
    « Reply #7 on: 03/13/10, 02:36 »
    If you have components and variables, you should not have more than one frame in this movieclip.
    Otherwise things are getting a little complicated ;)

    I allways hav a base movieclip with all the code, consisting of a single frame.
    All animation is done ba child movieclips loaded from this base.
    These ChldClips rarely have code, to keep things together.

    If you oragnaized to keep variables together, you will not lose the contact ;)
    So you can allways read the content of former read variables, as long as you know where they are ;)

    After you are working with MX and AS2, you have _global or _root, as a base, where you can store variables to be used by all the movieclips around.

    With AS3, you should be using classes/objects to manage data.
    happy flashing
    8)
    Ronald

    jhoward

    • Server what's that
    • *
    • Posts: 11
      • View Profile
    Re: LoadVars to load image data from database
    « Reply #8 on: 03/18/10, 20:31 »
    Hi again RW, I am once again just a step away from finishing my project and reached a dead end.
    Quickly, to clarify I am using AS2 and MX Pro 2004

    In my main frame I have MovieClip1 which contains 2 dynamic text fields and another button or movieclip ...(need your choosing which is best here) I have tried both. I have checked the values of my variables from my aspx page and they are fine

    Below is the code for the action of "MovieClip1": (my main mc)

    onClipEvent(load)
    {   
    var myLoadVars:LoadVars = new LoadVars;
    loadMovie("http://localhost/dpob/flash/FlashPhoto_A.jpg",mc_button1) //used for another peice of the puzzle
    myLoadVars.load("http://localhost/dpob/flash/flash.aspx?fid=1");
    myLoadVars.onLoad = function(success:Boolean){
       if(success){
          VarStrTitle.htmlText = this.VarStrTitle;
          VarStrSubTitle.htmlText = this.VarStrSubTitle;
          VarLink.htmlText = this.VarLink;
          }
       }
    }

    Now, for that button (or MovieClip) that I mention above I need to have the value of the variable named "VarLink" to be used as  the URL that I send to a new browser window when the button is clicked. I have primarily tried using the folling in the action of the button:

    on (release) {
    Geturl(_parent.VarLink,"_blank")
    }

    I have also tried a bunch of othercombinations using _root,_global,_level0, etc...nothing works. If I hard code a URL in place of the var I am calling it work perfectly, just cant get that damn value.

    This seems so damn easy yet I have speant a week going througha 1000 different sets of code and cannot get this to work. Currently I get "undefined" as my URL. In a previous set of code I used LoadVariables instead of LoadVars and got the link to work but experienced issue with it adding a bunch of other code. regardless I seem to understand that LoadVars is the way to go.

    In the following example you will see what I am doing visually. "PAGE ONE" of this example shows what I want. The large image and two lines of text are coming back from the aspx and DB. Hell I even already have the exact URL that I need being passed to one of the dyanmic text areas where it says "Downtown Dining promotions Will..... click here" (that "click here" takes you to the proper URL.

    I am at my whits end here. Any help and example of code would be greatly appreciated!

    Thanks,
    j
    « Last Edit: 03/18/10, 20:34 by jhoward »

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: LoadVars to load image data from database
    « Reply #9 on: 03/19/10, 01:32 »
    if you want to make the variable be accessible globaly, you have to define it in _global.

    Code: [Select]
    _global.myLoadVars=new LoadVars();
    _global.myLoadVars.load(...
    etc.

    then you can allways, no matter where you are, access it by _global.myLoadVars.VarLink etc.
    happy flashing
    8)
    Ronald

    jhoward

    • Server what's that
    • *
    • Posts: 11
      • View Profile
    Re: LoadVars to load image data from database
    « Reply #10 on: 03/19/10, 08:08 »
    Ok, that at least gets me back to where I was with using LoadVariables. I now have the same issue I did at that time however. Both in localhost and on production server I click on the link which should take me here: http://www.godowntownbaltimore.com/Entertainment/dining.htm

    ...but this (below) is what it does to my URL instead: (which results in a bad request)
    http://www.godowntownbaltimore.com/Entertainment/dining.htm%3C!DOCTYPE%20html%20PUBLIC%20%22-//W3C//DTD%20XHTML%201.0%20Transitional//EN%22%20%22http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd%22%3E%3Chtml%20xmlns=%22http://www.w3.org/1999/xhtml%22%3E%3Chead%3E%3Ctitle%3E%3C/title%3E%3C/head%3E%3Cbody%3E%20%20%20%20%3Cform%20name=%22form1%22%20method=%22post%22%20action=%22flash.aspx?fid=1"%20id="form1"><div><input%20type="hidden"%20name="__VIEWSTATE"%20id="__VIEWSTATE"%20value="/wEPDwULLTE2MTY2ODcyMjkPFgIeA2ZpZAUBMWRkdWptt07XrN1C9xvKYqcdiA3QQjc="%20/></div>%20%20%20%20</form></body></html>

    Any idea why this is being passed to the browser?

    Here is my code again.
    onClipEvent(load)
    {   
    _global.myLoadVars = new LoadVars;
    loadMovie("FlashPhoto_A.jpg",mc_button1)
    _global.myLoadVars.load("flash.aspx?fid=1");
    _global.myLoadVars.onLoad = function(success:Boolean){
       if(success){
          VarStrTitle.htmlText = this.VarStrTitle;
          VarStrSubTitle.htmlText = this.VarStrSubTitle;
          VarLink.htmlText = this.VarLink;
          }
       }
    }
    ----------(Below is action of my button MovieClip)----------------
    on (release) {
       getURL(_global.myLoadVars.VarLink,"_blank");
    }

    Thanks for your very quick reply.

    J

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: LoadVars to load image data from database
    « Reply #11 on: 03/19/10, 14:01 »
    this is, because varLink is a textfield, not a variable only, use varLink.text to call the page.
    « Last Edit: 03/19/10, 14:04 by Ronald Wernecke »
    happy flashing
    8)
    Ronald

    jhoward

    • Server what's that
    • *
    • Posts: 11
      • View Profile
    Re: LoadVars to load image data from database
    « Reply #12 on: 03/19/10, 18:13 »
    Well VarLink is not a text field any longer. I need it to be the link to the browser window. I am either tring to do this by creating a button or a MovieClip with the following in its action:

    on (release) {
       getURL(_global.myLoadVars.VarLink,"_blank");
    }

    making it a textfield and adding varLink.text just displays the link in a text field.

    I am missing something very obvious here.

    Thanks,
    j

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: LoadVars to load image data from database
    « Reply #13 on: 03/20/10, 01:04 »
    try to trace the values, if you can access them
    happy flashing
    8)
    Ronald

    jhoward

    • Server what's that
    • *
    • Posts: 11
      • View Profile
    Re: LoadVars to load image data from database
    « Reply #14 on: 03/21/10, 18:19 »
    Im not sure I understand.

    More simply put, I guess I am hoping you can tell me the proper way to handle this:

    In my first frame:
    - In the first frame of my flash I am loading my variables from aspx
    - In that frame I have added a Movie Clip (MovieClip1)
    - In that movie clip I have added two dynamic text areas, and 1 other object called "mc_button1" (to be either a button or Movie clip acting as a button)
    - I am also loading an image with LoadMovie and assigned to that same object "mc_button1" so that the image that is loaded, actually becomes the hit area of the button when clicked.

    I thought I would simply add the below to that mc_button1 object, but I guess not?
     
    on (release) {
       getURL(_global.myLoadVars.VarLink,"_blank");
    }

    Here is my project: http://www.godowntownbaltimore.com/flash/flash.html (Page one is the only one I am currently concerned with)


    Thanks again, sorry for being a slow student.