Moving an image with actionscript

I'm trying to move an image from position Y:0 to Y:-100 using
actionscript when the .swf file loads, as this is smoother than
conventional tweening??

Well Sim-Enzo is almost correct. You will have some problems
though because it is not really complete.
When you want to do things over time (move, fade, scale,
etc.) with actionscript you have two main choices –
onEnterFrame and setInterval. For the example given by Sim-Enzo I
would rewrite it like this:
myImageClip.onEnterFrlame=function(){
if(this._y>-100){
this._y-=10;
}else{
delete this.onEnterFrame;
this._y=-100
Here are why I would make these changes.
First the onEnterFrame is poorly named and confuses a lot of
folks. So remember onEnterFrame means "do this next bit of code at
the frame rate of the movie – even if the timeline is stopped
or there is only one frame."
Next. Each movie clip instance can only have one onEnterFrame
handler defined for it. So it is a good idea to assign each one to
an appropriate clip to avoid problems. By attaching this one to the
clip you want to move, myImageClip, you will also be able to assign
other ones to other clips and do whatever they need to do.
Then inside the event handler, notice how I refer to the clip
by "this" since the onEnterFrame is scoped to the myImageClip.
Finally, and this is probably most important, I have added an
else to the conditional. This makes sure that once your clip has
move to where it is supposed to go that the onEnterFrame is
stopped. Otherwise the onEnterFrame would just keep going –
it wouldn't move the clip anymore, but it would be using up
processor time. One errant onEnterFrame like this wouldn't probably
bring down your swf, but if you didn't do it with many different
ones you would notice.
I also added a little bit there which put the clip exactly at
the place I wanted. There are times in Flash where rounding errors
or other issues can make for surprises. I think it is good practice
to set the value to the exact required value.

Similar Messages

  • Create an image with ActionScript

    How do you create an image with ActionScript? The image is
    located at an url that is not guaranteed to be on the same server.
    I would prefer something that is compatible with previous
    versions of the Flash player.
    If you could point me to some tutorial or show me how it is
    done.
    Thanks

    This is suuuuuuuuuuuuper basic, you just have a movieclip on
    the stage and the URL of any image on the internet/local computer
    function loadImage(imageUrl:String,
    holder_mc:MovieClip):Void{
    holder_mc.loadMovie(imageUrl);
    Fill the two parameters with the 1. image url and 2.
    movieclip that holds the image
    It will load the image into it. Much more in depth tutorials
    and stuff can be found all over the place, just google it.
    Sam

  • Moving movie clips with ActionScript

    I am trying to move four movie clips with actionscript in a
    circler motion with two buttons, one to rotate the mc’s to
    the left and one button to rotate the mc’s to the right. Here
    is a link to what I am trying to do;
    http://www.us.playstation.com/Lair/
    and it is undrer game features.

    Yes, that's what the code I gave you is intended to do....
    you replace that code with whatever action you need to take to turn
    your movie around.
    I have no idea what your movieclip is doing, but I'm guessing
    by your response that if it was an arrow pointing left to right
    (just an example), you want it to be pointing right to left when
    the left arrow is pressed. If you want an immediate turn around,
    then the simplest way to do that is to have another frame
    containing the movieclip that it moves to where it faces the other
    direction--and to have it appear turned around, from the toolbar
    you select Modify -> Transform -> Flip Horizontal.
    So the movieclip would live inside another movieclip that has
    two frames with stop()'s for each frame. In the first frame you
    would have the subclip facing left to right, and in the second you
    would have it facing right to left. If we call that 2-framed
    movieclip "walker", the code I provided before would
    become...

  • Moving symbol instances with actionscript

    I'm just looking for a primer of sorts... I want a symbol to
    slide around on the stage when various buttons are clicked.
    I know how to set new _x and _y values for it, but that will
    just make the instance jump across the stage. I want it to slide -
    even ease out of the slide as it ends it's motion... I know this
    can be done, but have no idea where to start looking in regards to
    "how".
    Thanks for you help - which can come in the form of a
    tutorial, tips, snippets of code, etc.
    later - Chris

    Well Sim-Enzo is almost correct. You will have some problems
    though because it is not really complete.
    When you want to do things over time (move, fade, scale,
    etc.) with actionscript you have two main choices –
    onEnterFrame and setInterval. For the example given by Sim-Enzo I
    would rewrite it like this:
    myImageClip.onEnterFrlame=function(){
    if(this._y>-100){
    this._y-=10;
    }else{
    delete this.onEnterFrame;
    this._y=-100
    Here are why I would make these changes.
    First the onEnterFrame is poorly named and confuses a lot of
    folks. So remember onEnterFrame means "do this next bit of code at
    the frame rate of the movie – even if the timeline is stopped
    or there is only one frame."
    Next. Each movie clip instance can only have one onEnterFrame
    handler defined for it. So it is a good idea to assign each one to
    an appropriate clip to avoid problems. By attaching this one to the
    clip you want to move, myImageClip, you will also be able to assign
    other ones to other clips and do whatever they need to do.
    Then inside the event handler, notice how I refer to the clip
    by "this" since the onEnterFrame is scoped to the myImageClip.
    Finally, and this is probably most important, I have added an
    else to the conditional. This makes sure that once your clip has
    move to where it is supposed to go that the onEnterFrame is
    stopped. Otherwise the onEnterFrame would just keep going –
    it wouldn't move the clip anymore, but it would be using up
    processor time. One errant onEnterFrame like this wouldn't probably
    bring down your swf, but if you didn't do it with many different
    ones you would notice.
    I also added a little bit there which put the clip exactly at
    the place I wanted. There are times in Flash where rounding errors
    or other issues can make for surprises. I think it is good practice
    to set the value to the exact required value.

  • Slice image with actionscript

    Hi,
    I want to create animation. I want to slice image into random number of rectangles (it can't be squares) and I want to animate all of this rectangles at once.
    Any ideas?
    Best whishes,
    sledz

    Use BitmapData class:
    read original BitmapData --> read pixels that fit into rectangles (getPixels method) --> create Bitmaps out of individual rectangle's BitmapData --> animate Bitmaps.
    Documentation:
    http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.htm l
    http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/Bitmap.html
    Also search for BotmapData tutorials - there are a lot of them.

  • Need help displaying images with List component for Flash CS4 (ActionScript 3.0)

    Hi folks:
    I am an inexperienced user of Flash CS4 Pro (v10.0.2). I am attempting to use the List component with ActionScript 3.0 to make a different image display when a user clicks each item in a list.
    I did find a tutorial that showed me how to make different text display using a dynamic text box and the following ActionScript:
    MyList.addEventListener(Event.CHANGE, ShowSelectedItem);
    function ShowSelectedItem(event:Event):void {
        ListText.text=MyList.selectedItem.data;
    ...where My List is the instance of the List component and ListText is the dynamix text box. In this case, the user clicks an item in the list, defined by the label value in the dataProvider parameter of the List component, and text displays as defined in the data value in the dataProvider parameter.
    However, as I mentioned to start, what I really want to do is make images display instead of text. Can anyone provide me the steps to do this?
    I appreciate your help (in advance)!!
    Cindy

    Hi...thanks for responding! I was planning on using images from the Library, but if there is a better way to do it, I'm open. So far, I just have text in the data property. This is part of my problem. I don't know what I need to put in the data value for an image to display. Do I just put the image file name and Flash will know to pull it from the Library? Do I need to place the images on the stage on different frames? I apologize for the "stupid user" questions, but as you can tell, I'm a newbie.
    Appreciate your patience and any help you can offer!
    Cindy

  • Want to add an image but with actionscript not a s:Image

    hi. i've looked for a good answer but can't seem to find one...i have a few images i want to add to my app at run time and don't want to use a whole lot of <mx:Image> components...just want to do it with actionscript. i get to the point where i've got an Image object and embedded the source of the Image object but don't know how to add the Image to the display list? thx

    on the same issue...i'd like to use some of the functions of the Sprite class....so i've got my image and added that to a Sprite object but can't seem to add the Sprite to any of the spark/mx containers...keep getting this error:
    Main Thread (Suspended: Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.)
    spark.components.supportClasses::SkinnableComponent/addChild
    play/init
    play___play_Application1_creationComplete
    flash.events::EventDispatcher/dispatchEventFunction [no source]
    flash.events::EventDispatcher/dispatchEvent [no source]
    mx.core::UIComponent/dispatchEvent
    mx.core::UIComponent/set initialized
    mx.managers::LayoutManager/doPhasedInstantiation
    mx.managers::LayoutManager/doPhasedInstantiationCallback

  • Moving images with alpha

    In Pages '09, images with alpha channels can be difficult to deal with, especially if the alpha is a bigger part of the object than the non-alpha portion.  The issue is that you cannot move an object by clicking on an area that is transparent.  For most images, this is intuitive and helpful, but for some things it is infuriating.  For example, when pasting in a PDF or image object of a MathType equation, it is quite difficult to reposition the image quickly, because great care must be taken to click on a letter in order to drag the object.  To make matters worse, the edge detection of the non-alpha portions of the object is not extremely precise, so it can appear that you are clicking on a legal part of the image, but you will get no response from pages.
    My question is this: do any of you know if there is a preference somewhere that controls whether alpha is selectable or not?  I would just like to be able to click anywhere in the image box and move the image.  It doesn't matter if it is a support preference or requires fiddling with a plist somewhere.  Anything would be helpful.  Thanks.

    Dream on,
    Well, the World needs more Yoyo Ma types, so I hope you are successful.
    If you Command-Click in the Margin and Drag across the page, you will catch the object in a wide net. Then you can manipulate it with the arrow keys, or Shift-Arrow for larger moves.
    Jerry

  • Moving Images with the mouse

    Sorry I am still fairly new to Java. I have a project due that will require me to move images with the mouse. And I was wondering if someone could give me the basics of doing this. Right now I only need to know how to move the image any where on the screen.

    sweety_baby wrote:
    It's not so usefull nebody plzz help me i wanna code for movinag an image from one place to another in frame
    plzzzzzzzz help me out its urgentIf it's so d�mn urgent, then why
    1) dredge up a thread that's more than 2 years old, and
    2) provide us with hardly any information about your problem, what you've done, what's worked, what's failed.
    Result: request denied.

  • How can I use LCCS with ActionScript 3 and Flash CS4?

    Hi,
    Using Stratus I was able to create an an application using Action Script 3 and Flash CS4.  The sample code on the Adobe site was quite straight forward and easy to understand.  I now want to switch over to  LCCS but can't find anything any where on how to use Action Script 3 and Flash CS4 with LCCS.  Do I need to know Flex to be able to use LCCS?  Everything was quite simple and easy to understand with Stratus and makes complete sense.  But LCCS is really confusing.  Is there any sample code on how to establish a connection in Action Script 3 and then stream from a webcam to a client.  There is nothing in the  LCCS SDK that covers Flash and Action Script 3.  Please help!  I found the link below on some forum but it takes me nowhere.
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=72&catid=75 9&threadid=1407833&enterthread=y

    Thanks Arun!
    Date: Thu, 29 Apr 2010 11:44:10 -0600
    From: [email protected]
    To: [email protected]
    Subject: How can I use LCCS with ActionScript 3 and Flash CS4?
    Hi,
    Welcome to the LCCS world.
    Please refer to the SDK's sampleApps folder. There would be an app called FlashUserList. The app demonstrates how LCCS can be used with Flash CS4. Its a  pretty basic app, but should help you moving.
    We are trying to improve our efforts to help developers in understanding our samples. Please do let us know if we can add something that would help others.
    Thanks
    Arun
    >

  • Using still images with Final Cut (and the apple suite in general)

    I have had a re-occuring and long term problem that has caused me many lost hours of head scratching and work arounds, and as of yet I have not been able to come up with a good solution.
    Its to do with integrating still images with the Final Cut suite.
    If I receive a high quality image from a client to use in their video and I then try importing it into Final Cut and animating it, it always ends up looking like a pile of ahem. Often I will get "swimming" lines appear across fine detail on the image, and parts of it will flicker as it moves across the screen. For instance, if I have a picture of some blinds or other fine detail (especially horizontal and vertical lines), when I add a grow and throw movement to it the detail will become very noisy - buzzing and flickering like mad.
    I have found I can counter this by resizing the image in photoshop to a resolution closer to SD video (700w or 500h) - but I always end up losing detail, and the flickering and noise is only reduced, not eliminated. Other things that have helped are blur effects applied at a very low level, like 0.5 blur, so its not noticeable visually, but Final Cut seems to treat it differently and quieten the noise and flicker down.
    However, all of these workarounds are ultimately still giving a reduced quality product.
    Also, this problem is not necessarily constrained to Final Cut, I am currently fighting DVD Studio Pro because it is murdering the text quality in a stills slideshow I am creating - and in this situation there is no animation being applied. No matter what file type (psd, jpeg, tiff, png...) or size I output the text and images from Photoshop in, the moment DVD studio pro gets hold of it, it turns to cripe.
    For a while I was putting it down to the fact that I usually edit in SD (PAL) formats, and there just wasn't the resolution available to reproduce fine detail. However, I do often see other people achieving pin-sharp fine detail on still images and text in SD formats (the Apple templates are a good example)
    So, my question to you, oh great and high boffins, if you are dealing with still images and text, how do you do it? How do you work around any noise problems you have, and how do you produce those pin-sharp images (both moving and still) I see in other professional productions?
    Quad G5   Mac OS X (10.4.8)  

    still images with too high a resolution will always cause problems. this is due to the detail of the image being finer than the scanline of the tv can display ... obviously this will caise the image to flicker as these details alternately appear and disappear as and when the scanline can display them. as you have discovered, the answer is to apply a very small blur, the effect being that the detail is spread by the blur such that the scanline can dislay it correctly.
    text issues are often rooted in the same problem ... unless the text is placed very carefully (whole even number on the y axis) then the quality may be impaired due to the resulting interlacing/scanline issues

  • Images with same name in different folders being swapped

    I've been out at a printers freelancing and using CS6 for the first time. I've a 64 page document with a large number of images (100+) that have been given various treatments and held in folders named to identify them.
    originals: sweden.jpg, germany.jpg, india.jpg…etc
    saturated: sweden.jpg, germany.jpg, india.jpg…etc
    greyscale: sweden.jpg, germany.jpg, india.jpg…etc
    and so on. The document contains differnt combinations of these pictures, all in all I've about 1,000 image links in the document.
    I opened up my document this morning and found for some reason the links to the images were broken - no idea why as no folders seem to have been moved but when I relinked to one of them - say a greyscale image - they ALL linked to the wrong set - the "saturated" ones. Looking at the image path in the links panel I see that's what's happened, ALL the link paths to ALL the images say "saturated", never mind the fact they're greyscale in the document.
    So is this a known issue? At the moment I can't find any solution but to relink manually over a thousand images, which, lets face it, is a bit of a disaster for me and the job deadline.
    I've used indesign for years and never come across anything even CLOSE to this sort of behaviour.

    InDesign has a feature that will automatically search for other missing links when you fix a missing link. When you relinked the first of your grayscale images, you may have accidentally relinked to the saturated image. When this happened it searched the directory that the newly re-linked file was in for all the other missing files. Since your image names all matched up to images in that directory, they all got re-linked.
    This auto-relink feature can be toggled in the relink dialog:
    If you have a backup of your file, you can revert to that version, and try to relink your images from that one. In the future you should make sure that images all have unique identifiers, it is bad practice to have images with identical names.

  • Printing Images with Transparent Background

    Sorry if this question has already been asked, but I couldn't find anything similar to it in a search through the archives.
    I have a couple of images with transparent backgrounds in a document, much like the shells and the blue flowers in the "Classic Brochure" template in Pages 2.0.1. These images show up perfect on the screen, and when printed as .pdf files, but when I print to either an hp color laserjet 4600 or an hp laserjet 1320, the images show up with a clear box around them; the colors under the box (where it should be transparent) are faded and slightly blurred. This happens both with my document, and the unaltered "Classic Brochure" template. I've tried moving various objects backwards and forwards, but it doen't seem to have any effect. It even happens with one of the text boxes I have in the document.
    Another odd thing is that the printed "box" isn't the same size as the box that appears when you click on the object in the document. It's a bit bigger. I've seen other posts about problems with hp printers, but I'm not sure it's related. Any insight would be appreciated.
    MAF
    iMac Intel Core Duo   Mac OS X (10.4.7)  

    http://indesignsecrets.com/eliminating-ydb-yucky-discolored-box-syndrome.php
    Bob

  • How do I import an image with an opacity mask from AI into FW

    I have created a graphic in AI which contains several images with associated opacity masks. The mask use a radial gradient to achieve the desired effect. I am unable to import these images into FW with the mask effects intact even though the layers appear to be there. What am I doing wrong? I don't see away to do it in FW directly. If there's a work-around that would be appreciated too.

    Fireworks' masking is pretty good. If you have your object and your mask in FW, arrange the objects so that the mask is above the object, select both, then click on
    Modify > Mask > Group as Mask
    Where the mask is white, your object will be fully opaque. Where the mask is black or 100% transparent, your object will be fully transparent. Where the mask is grey or partially transparent, your object will be, as well, proportionally to the grey level/transparency level in the mask.
    Fireworks also has some built-in masks to fade objects radially or linearly. In CS3, these are under
    Commands > Creative > Fade Image
    but they got moved someplace else for CS4. I can't find the info on that in the help, though, sorry. Oh wait. It might be the Auto Vector Masks:
    http://help.adobe.com/en_US/Fireworks/10.0_Using/WS29D46793-C43E-4941-960E-F238FB1977C8.ht ml
    Mask info here:
    CS3: http://help.adobe.com/en_US/Fireworks/9.0/help.html?content=frw_layers_la_19.html
    CS4: http://help.adobe.com/en_US/Fireworks/10.0_Using/WS4c25cfbb1410b0021e63e3d1152b00d169-8000 .html

  • Changing images with c#

    Hi,
    I am making a slotmachine. I have everything but only need an animation for changing the images. This is what i got(only the code for the animation). I can change 2 images but don't know how to do it with multiple images like 5.
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    namespace animatie
        public partial class Form1 : Form
            public Form1()
                InitializeComponent();
                Timer t = new Timer();
                t.Interval = 100;
                t.Tick += new EventHandler(t_Tick);
                t.Start();
            bool one;
            void t_Tick(object sender, EventArgs e)
                Image img;
                if (one) img = imageList1.Images[0];  
                else img = imageList1.Images[1];                      
                one = !one;
                pictureBox1.Image = img;

    Since it seems like you have it working for 2 images then expanding it to any # of images is straightforward. It looks like you're trying to animate the spinning wheel on the slot machine so that is the basis I'm working against.  I'm also assuming
    you want to stick with the image list but there are other approaches as well.
    Firstly make sure your images are all in the image list. Next I would recommend that you move the timer start logic out of your constructor.  You don't want it running when the form is created because it hasn't even been displayed yet.  If you
    want the spinning to start as soon as the form is displayed then override the OnLoad and start the timer at that point.  I would recommend that you move this functionality into a separate method because you'll probably want to be able to spin the wheels
    by clicking a button as well. 
    Since you're using an image list you'll need to keep track of the "current" image.  To do that a simple image index field should be fine.  Each time the timer fires you increment the index by 1.  If it gets to the end of the list
    (>= count) then reset it to 0.  Then set the PictureBox image to the image at that index.  This gives you the wrapping logic you want.  It won't give you a smooth transition image though, each image will basically just pop up. 
    If you want a smooth transition then you might need to look at using a single image with images on it and the timer is simply having the window viewport move "down" the image in a scrolling fashion.  When it gets to the bottom it loops back
    around.  For that kind of implementation a PictureBox is probably not a good idea, you'll want to use a simple custom control that handles its own painting instead.
    Since you'll need to do this 3 times (one for each window) you might consider moving the logic into a custom control that represents a single window, the timer logic, image selection and image list.  You can then use 3 instances on your form to emulate
    the slot machine.  Note that you'll want to add some randomness to the spinning because if each window spins at the same speed you'll always get the same behavior.  Therefore you should probably have each window randomly decide how long and how fast
    to spin to introduce randomness to the spinning.
    Michael Taylor
    http://blogs.msmvps.com/p3net

Maybe you are looking for

  • Raid 0 for dual SSD's in optical drv together with RAID 5 in internal bays

    Hi, I would like to add two 100GB SSD's in the second optical drive space in RAID 0 for boot. This can be done with a special bracket and cables to the SATA connections on the motherboard. So far so good. Now I have 4 drive bays I could fill with 4x2

  • Using a Sony CPA-9C Car Cassette Adapter with a Muvo TX

    I have a Sony CPA-9C Car <B>Cassette</B> Adapter which works great with CD players. However, with the Muvo TX FM there is little or no amplification. Even at full blast - both the car stereo and the player, the sound is barely audible. Is there any f

  • Problems with Terminal. :(

    HI everyone, I was starting up my minecraft server when I unforrunately got this error message: login: PAM Error (line 400): System error /Users/Paolo/Desktop/Paolo\'s\ server/start.command ; exit; [Process exited - exit code 1] Can anyone help me? I

  • Ipod touch doesn't open itunes automatically

    My wife and I are both noticing that when we plug our iTouches into our Snow Leopard OS computers that iTunes does not automatically open up. This is something that has only happened during the past week after upgrading the iOS/iTunes softwares. We n

  • Java RFC Class Library

    Hi, I'm an SAP programmer (not a Basis person).  I want to write a Java application (using Eclipse) that has to communicate with SAP backend system.  Where can I find Java RFC Class Library to install on my laptop?  I have SAP Frontend installed on m