Groups | Blog | Home
all groups > flash actionscript > july 2007 >

flash actionscript : dynamicly swap image in a movie?


false_vapor
7/6/2007 7:55:08 PM
Hi everybody.
I'm trying this:
I have a movie clip which does something with a graphic (jpg).
I have a boutton as well on which I want to load different jpg from a url into
that movie clip and then replay.
That way I'm hoping to crate one of those slide shows that performs that same
movie on different images.
I figured out a way to load images dynamically into the movie (using
themovie.addChildAt(loader,index), right?), but I'm having hard time figuring
out how to swap the current graphic in that movie with newly loaded. That movie
will go back to the first frame but wont play again with new image.
Also I want to align the new image to the movie as the original was aligned
and that is also unclear for me.
Please help! Thanks a lot in advance.



kglad
7/6/2007 8:49:36 PM
false_vapor
7/6/2007 9:08:04 PM
Hi, kglad! Thanks for reply. Sorry I figured that out. Now I only need to
understand how to align images programmatically (since they are potentially
different sizes) to the movie clip. In same same manner as in UI the align tab
with Align,distribute,Match size,Space.
kglad
7/6/2007 9:22:27 PM
false_vapor
7/9/2007 4:43:04 PM
Hi again. I have the original movie clip which does something with a jpg (moves
it around the stage). Then I have "next" button that takes a next jpg, replaces
the original with it, and supposed to move it around in the same exact way
around the stage. It's a slide show. Positioning of the original image within
that movie is done via UI aligning tools. Since pictures could be different
proportions the alignment (putting the image in center for instance) will be
screwed up. So I want to tell Flash to recenter new jpg within this movie clip
somehow.
kglad
7/9/2007 5:20:21 PM
AFTER loading is complete you can access the loaded image's width and height
and center it using:

loader.x=yourMC.x+(yourMC.width-loader.content.width)/2;
loader.y=yourMC.y+(yourMC.height-loader.content.height)/2
false_vapor
7/10/2007 10:22:19 PM
Ok. Thanks a lot! That helps! Now I need to dup the newly loaded jpg into a different movie clip let's say for reflection effect.
What do I dup? The loader? The content of the loader?
kglad
7/11/2007 2:02:11 AM
you can't do that. just (re)load the jpg into a different target movieclip.

if you wait until the first jpg is completely loaded subsequent loads are
pulled from the user's cache and so consume less than 1 second of download time.
false_vapor
7/11/2007 1:57:23 PM
Oh. Interesting! Ok then. I'll do that.

Just so I understand in general:
what was duplicateMovieClip function in AS2?
AS3 documentation says that it was replces by new instances of MovieClip class.

Thank you for all your help!
kglad
7/11/2007 2:07:39 PM
duplicateMovieClip() is the as2 function that duplicates movieclips.

you can write global code anywhere in your fla. just prefix global variables
and functions using the _global keyword whenever you assign their value.
false_vapor
7/11/2007 2:15:32 PM
I see. That's great! Now I'm on fire!
kglad
7/11/2007 2:21:08 PM
you're welcome.

false_vapor
7/11/2007 3:47:56 PM
Wait! I'm stuck again. _global doesn't exist in AS3, right? It's only AS2. So
I'm trying to work with static functions and vars and the the thing now
complains that I can't have nested classes in FLA. But I have no classes other
than the one I declared on flame 1 of the top level MovieClip.

:embarrassment; :confused;
kglad
7/12/2007 4:57:55 AM
you can create a public class with a public static property that's an object.

false_vapor
7/12/2007 2:29:06 PM
But when I add to the first frame of the top lever movie clip:

public class GrafLoader
{
}

it complains with "1114: The public attribute can only be used inside a
package."
without public:

class GrafLoader
{
}

it complains "1131: Classes must not be nested." But there are no classes in
which this one sits. It's just at "Scene 1, Layer 1, Frame 1, Line 8".
I get a feeling that I can't declare classes in FLA files. Somewhere else?
kglad
7/12/2007 8:18:01 PM
in as3 (and as2, for that matter), class files must be in a .as file. the file
name must match the class name (case counts). in as3, every class file must be
in a package.

so, you can use:



package{ // save as glo.as
public class glo{
public static var bal:Object=new Object();
}
}

// you can now access glo.bal from anywhere (as long as your fla has a path to
glo.as). so, for example,

glo.bal.myGlobalVar ="hi"; // is available from all your classes and
timelines.
false_vapor
7/12/2007 8:24:53 PM
Thanks a lot! All this matching names is really what threw me off.
kglad
7/12/2007 8:28:58 PM
false_vapor
7/12/2007 8:59:21 PM
Well. ....... aaaaaaaaaaaaaAnd the last question: :D
How would I pass a function that has a string parameter as a parameter into another function for call back.
AddThis Social Bookmark Button