Link to home
Start Free TrialLog in
Avatar of Chris99
Chris99

asked on

I want to write a simple program in Flash

I'm totally new to ActionScript, and I'm pretty new to Flash too, I had a few classes a couplea years ago, and that's about it.

Long term goal:  I'd like to write an .exe file that randomly picks images from a directory or directories and shrinks or zooms them and puts them in random places, maybe altering their appearance in an interesting way.

Short term goal:  I want to write a flash program that will, upon being executed, :

Detect the monitor size and fill the screen
Pick a jpg file from a directory
Resize the jpg if necessary to be no higher than the screen height (without distorting the image)
Display it centered in the middle of the screen
Display it for ten seconds
Quit

After this much is accomplished, I'll post another question which will modify this basic program to do more sophisticated stuff, like pick a random file from a directory, resize the file to a random size, crop the file randomly, etc.

I don't really mind if you guys write the code for me, but best-case-scenario would be me learning as I go and being able to make my own modifications.

Thanks for looking!

Chris
Avatar of Rob
Rob
Flag of Australia image

Hi!,

To fill the screen you can use the fscommand with fullscreen = true;
Flash cannot traverse directories but given files it can load them

Is the resize part of the animation or you want the image resized before it is shown?

to display it in the middle of the screen or resize the image you (conceptually) need to load the image into flash and wait until it has fully loaded.  when that has happened then you can resize and centre using some simple maths :)  to centre is (Stage.width - image._width) / 2.   to resize to a certain height say the screen height, you would increase the width in the same ration to how the height changed.  ie.

var targetHeight:Number = Stage.height;
var ratio:Number =  (Stage.height / image._height);
image._width = ratio * image._width;
image._height = Stage.height;

you can use the fscommand again with quit this time to close your app

see how you go with this but it should get your started
ola. just to add to tagit's comments - as i'm busy helping a client with a similar thing right now.
in terms of what you don't understand have a look at the flash help files (F1) for examples and an explanation.

1. Detect the monitor size and fill the screen -
>> as tagit says, the fscommand and allowscale options will sort that out for you so you don't need to know the screen resolution.

2. Pick a jpg file from a directory
>> I'd suggest using an xml file to store the images names from the directory, and then have flash load the xml with the image names/paths, then loading the actual image or alternatively specify path ... ./images/image1.jpg for example.
Using the MovieClipLoader option is the best - an example from the help file

var container:MovieClip = createEmptyMovieClip("container", getNextHighestDepth());
var mcLoader:MovieClipLoader = new MovieClipLoader();

using the movieclipLoader yu have the ability to use listeners to check if there are errors, when the loading is complete etc. once complete then you can check the size of the image and resize as necessary (or use a mask).
mcLoader.addListener(this);
mcLoader.loadClip("YourImage.jpg", container);

function onLoadInit(mc:MovieClip) {
    trace("onLoadInit: " + mc);
}

in terms of altering the appearance in an interesting way, you can apply some effects at runtime, but not much, and i guess it depends what you consider interesting, (for e.g. an alpha transition).

display in the centre of the stage, do some math, work out the centre point, and some more maths ...... (arrrggh)

display for ten secs - if using AS3 use Timer class - in AS2.0 you can use setInterval.

quit - (exit exe???) - or change image????

there's a lot involved in this but if you're wanting to learn and aren't on a deadline, follow the guidelines offered by the nice ppl here and have a nosey around the help files, and you'll get there.

enjoy. blu.








Resize the jpg if necessary to be no higher than the screen height (without distorting the image)
Display it centered in the middle of the screen
Display it for ten seconds
Quit
Avatar of Chris99
Chris99

ASKER

Okay...thanks guys.  So would using a different programming language than flash be better, more suited for what I'm trying to accomplish?  I asked a question previously about what program to use and was told flash or C++ would be best.  I went with flash, since I had a copy, but if C++ would be better or easier I'd rather go with that.


Okay so I open Flash...
I click "New ActionScript file"
Blank screen...
I've stuck together the following code, which I'm sure is wrong, but here it is anyway:

var container:MovieClip = createEmptyMovieClip("container", getNextHighestDepth());
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(this);
mcLoader.loadClip("C:\Documents and Settings\Chris\Desktop\sample.bmp", container);

function onLoadInit(mc:MovieClip) {
    trace("onLoadInit: " + mc);
}

package {
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.display.Sprite;

    public class TimerExample extends Sprite {

        public function TimerExample() {
            var myTimer:Timer = new Timer(1000, 2);
            myTimer.addEventListener("timer", timerHandler);
            myTimer.start();
        }

        public function timerHandler(event:TimerEvent):void {
            trace("timerHandler: " + event);
        }
    }
}

var targetHeight:Number = Stage.height;
var ratio:Number =  (Stage.height / image._height);
image._width = ratio * image._width;
image._height = Stage.height;


fscommand(fullscreen:true)
//  (I guess some code to show the picture?  Or did the above do that?)
// (some code to run the timer for X number of seconds here)
fscommand(quit)

So is this the way I should go about it?  Or am I way off base?  I told you I was a beginner.  ;-)


The closest thing to what I'm trying to achieve is a program called Photo Mishmash...a now-pretty-much-obsolete program you can see here:  http://www.seraline.com/mishmash.htm.  The "manual" link describes what it can do.  Heck, maybe I should figure out how to hack into the .exe file and modify it, rather than starting from scratch.  :-)
Avatar of Chris99

ASKER

(resized before it was shown is what I was going for...sorry, forgot to answer you.)
Flash will definitely be easier unless you are quite advanced.  It will also get you up and running quite a lot faster and you don't have to worry about compile issues etc.  That said, if you are trying to replicate something similar to the mishmash program then you will need more than just flash.  Flash has basic bitmap manipulation but you may have to code any manipulation yourself.

Ok... I've been testing your code above which has a few errors but I'll get something together and get back to you.
Avatar of Chris99

ASKER

Any news, tagit?
sorry chris99 I've been flat out on another project.

I have been thinking about this and sorry i haven't gotten back to you earlier... Your long term goal can't be achieved solely with Flash.  To get the mishmash of the photos you will need an something else like imagemagik or gd graphics libraries.  The good news is that you can have flash "talk" with php (for instance) to achieve this but if you want a fully installable product then that's why c++ was recommended to you (though visual basic or java woud be fine as well).

Let me know how far you want to go implementing the mishmash program
Hi Chris, Where did you get to with this?
Avatar of Chris99

ASKER

Well I don't have C++, I do have Flash, so either I need to wait until I get C++ or go ahead and see what Flash can do.  Now I was told either Flash or C++ would be okay for this, it was a tossup.  But if C++ would be significantly better, I'd rather go with that so I wouldn't have to rewrite everything.

So are you saying that C++ is definitely the way to go?

Thanks,
Chris
If you want to create a screensaver then yes c++ will be the way to go and there are heaps of free compilers and IDE's available, a google search will do that for you.

if you are after a program to run at the users request to do what you want then the best option will be flash but the user will need to install some other software (imagemagik, gd etc) or you could use a combination of the two so that you get the looks of a flash app with the power of a c++

what's your ultimate end goal
Avatar of Chris99

ASKER

I think I'd rather it be standalone, ultimately; something someone could download and install and it would show up in the Windows screensaver list.

Are you saying I can get everything I need to do C++ for free?  If that's true, can you provide me with links to recommended editors to get what I need to start programming?

Chris
if you are designing this for windows then start here: http://www.microsoft.com/express/vc/ I would either start with c# or c++. If you would like it cross platform then c++ is the way to go.  For just windows try c#
Avatar of Chris99

ASKER

I think I'll go with C++, why not, although really I'd be surprised if I ever got to the point of having a finished, distributable program.  But hey, if I ever did, why not have it be cross-platform?

Is this C++ Express limited, and I'll have to buy the full version eventually, like Outlook Express?

Thanks, tagit, I hope you can help me when I post my question again in the C++ section.
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chris99

ASKER

Thanks tagit