A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Loading images with partial directory?

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    4

    Loading images with partial directory?

    I'm new to actionscript and I'm trying to keep this as simple as possible as to not get in over my head.

    I'm loading images into an empty movie clip, inside of another movie clip. This code is on each day of the year for five years with instance names changed for each. From here im trimming the file name and return the number after the decimal point which sets the transparency of the image.

    Code:
    loadMovie("images/jan/140108.70.jpg", P140108.empty_mc);
    
    var movieName:String = '140108.70.jpg';
    
    movieName = movieName.substring( 7, movieName.length - 4 );
    
    this.P140108._alpha = (movieName);
    This works fine. The issue im having is repeating this process many times with different images on each day and different transprencies. As you can image, changing the directories on every day for 5 years would take a long time...

    I was wondering if there was a way to return an image from a folder, based on only the first part of its url? If I could make it search for the date and ignore the .70 for example, I could change the transparency without having to change the code manually.

    I appreciate any advice you guys have.

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Here is something that can help you look for and load the correct image from the correct folder on a daily basis.

    paste this into a new fla and see what happens
    PHP Code:
    var TheAlpha:Number 70;

    function 
    GetImage()
    {
        
    // Declare New Date
        
    Today = new Date();
        
    // Number Month
        
    Months = ["01""02""03""04""05""06""07""08""09""10""11""12"];
        
    CurrentMonth Months[Today.getMonth()];
        
    // Get Day Number
        
    CurrentDay Today.getDate();
        
    // Get Year
        
    CurrentYear Today.getFullYear();
        
    // Folder Month
        
    FolderMonths = ["jan""feb""mar""apr""may""jun""jul""aug""sep""oct""nov""dec"];
        
    CurrentFolder FolderMonths[Today.getMonth()];
        
    // Display Date
        
    DateNow CurrentDay CurrentMonth CurrentYear;
        
    trace("Todays date formatted: " DateNow);
        
    // Display Folder to get image from with name
        
    FolderNow "images/" CurrentFolder "/" DateNow "." TheAlpha ".jpg";
        
    trace("Folder and image to get: " FolderNow);
        
    // load respective image
        //loadMovie(FolderNow, P140108.empty_mc);
        //this.P140108._alpha = (TheAlpha);
    }
    // Initially call function to get date ect
    GetImage();
    // Check for new date, currently set at every 1 hour
    GetNew setInterval(GetImage3600000); 
    this currently does not load an image (it can) because I am not sure if you will always be using the same empty movieclip to load into and I'm not sure if you are wanting the dates you have already written down (140108, I assume is 14th /Jan / 2008) ? or current dates ?
    Last edited by fruitbeard; 05-12-2013 at 01:17 PM.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    4
    Hi Fruitbeard,

    I should have mentioned I can't use any server side scripting for this project, it will be a standalone art project. I've been struggling to find anything to get around this issue not using PHP.

    The same movie empty movieclip is always used (empty_mc) and the dates are always going to be the same. Yep, 140108 is 14th Jan 2008.

    Thanks for the help, any ideas?

  4. #4
    Junior Member
    Join Date
    May 2013
    Posts
    4
    Hi Fruitbeard, thanks for the reply.

    I should have mentioned, I can't use any server side language for this project. It is going to be a standalone art project, hopefully.

    The images always load into the same empty movieclip (empty_mc) and im using a consistent set of dates Jan 14th 2008 - December 31st 2012. Yeah you're reading that date correctly as well 140108 is 14th Jan 2008.

    Thanks for your advice, hoping you might have another way around this problem?

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    this does not use server side language, I just put the code inside php brackets out of habit.

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    If you were to get it working today then this would follow suit from now on.
    PHP Code:
    var TheAlpha:Number 70;

    function 
    GetImage()
    {
        
    // Declare New Date
        
    Today = new Date();
        
    // Number Month
        
    Months = ["09""10""11""12""01""02""03""04""05""06""07""08"];
        
    CurrentMonth Months[Today.getMonth()];
        
    // Get Day Number
        
    Days = ["02""03""04""05""06""07""08""09""10""11""12""13""14""15""16""17""18""19""20""21""22""23""24""25""26""27""28""29""30""31""01"];
        
    CurrentDay Days[Today.getDate()];
        
    // Get Year - 5
        
    CurrentYear Today.getFullYear() - 5;
        
    CurrentYears CurrentYear.toString();
        
    CurrentYearFormatted CurrentYears.substring(2);
        
    // Folder Month
        
    FolderMonths = ["sep""oct""nov""dec""jan""feb""mar""apr""may""jun""jul""aug"];
        
    CurrentFolder FolderMonths[Today.getMonth()];
        
    // Display Date
        
    DateNow CurrentDay CurrentMonth CurrentYearFormatted;
        
    trace("Todays date formatted: " DateNow);
        
    // Display Folder to get image from with name
        
    FolderNow "images/" CurrentFolder "/" DateNow "." TheAlpha ".jpg";
        
    trace("Folder and image to get: " FolderNow);
        
    // load respective image
        
    loadMovie(FolderNowmovieclipname.empty_mc);
        
    movieclipname.empty_mc._alpha = (TheAlpha);
    }
    // Initially call function to get date ect
    GetImage();
    // Check for new date, currently set at every 1 hour
    GetNew setInterval(GetImage3600000); 
    just ignore the php tags

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Thinking about it, it would probably give wrong dates after a few months or with short months and so on.

    however if you were to rename your images and years to current dates then it would work very well,

    sorry to get your hopes up, still try it though if you wished to, it may do OK.

  8. #8
    Junior Member
    Join Date
    May 2013
    Posts
    4
    Thanks for clarifying the PHP tags.

    The code works fine but I'm not sure I understand it well enough to use it how I need yet.

    Currently it's tracing an output in the right format.

    Todays date formatted: 150108
    Folder and image to get: images/jan/150108.80.jpg

    But I don't see how it is deciding on the date, is it looking for todays date? I need to put code in each day of the year calling that days specific image and this needs to ignore the .80 extension untill it's loaded and then have it set the alpha of the image based on the extension.

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Its actually looking for today's date and deducting 5 years off the current year, it gets today's day and gets the relevant number from the days array, same with months, it so happens that you want your first month to be January so i made January 5th or 6th in the month array to counteract the difference, it will work fine for now, but I'm not sure how it will work further along the scale.

    if you follow.

    F

    you could however create long lists for each month/year and then make arrays from each and make it change after 24 hours or by the real time

  10. #10
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Just to add, I don't think you can load an image without the extension, it won't be able to find it without the extension applied to the linkage.
    having different numbers in the multiple image names would add endless headache to the loading code, I think.

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