MyButton with dynamically loading images

Hello!
I've tried to write my own button based on MovieClip. So I created a new MovieClip called MyButton. It has 3 main frames (or clue frames or... I don't know how it's called in English ): the first is for button's upState, the last two are the start and the end of press animation (I need a long animation - not just one frame). All the frames are empty.
Then I created a class MyButton.as:
package  {
     import flash.display.MovieClip;
     import flash.display.Loader;
     import flash.display.Bitmap;
     import flash.net.URLRequest;
     import flash.display.LoaderInfo;     
     public class MyButton extends MovieClip
          public var upState:Bitmap;
          public var downState:Bitmap;
          public var currState:Bitmap;
          public function MyButton(_upState:Bitmap, _downState:Bitmap)
               upState = _upState;
               downState = _downState;
               currState = upState;
               gotoAndStop(1);
               addChild(currState);
          public function pressed()
               gotoAndStop(2);
               removeChild(currState);
               currState = downState;
               addChild(currState);
               play();
          public function unpressed()
               gotoAndStop(1);
               removeChild(currState);
               currState = upState;
               addChild(currState);
and my main class is:
package my
     public class Main extends MovieClip
          var button_up:Loader = new Loader();
          var button_down:Loader = new Loader();
          var up : Boolean = false;
          var down : Boolean = false;
          var btn : MyButton;
          public function Main()
               button_up.contentLoaderInfo.addEventListener(Event.COMPLETE, compUp);
               button_up.load(new URLRequest("C:\\images\\back_up.png"));
               button_down.contentLoaderInfo.addEventListener(Event.COMPLETE, compDown);
               button_down.load(new URLRequest("C:\\images\\back_down.png"));
          function compUp(event:Event)
               up = true;
               if (up && down)
                    btn = new MyButton(Bitmap(button_up.content), Bitmap(button_down.content));
                    addChild(btn);
                    btn.addEventListener(MouseEvent.CLICK, my);
          function compDown(event:Event)
               down = true;
               if (up && down)
                    btn = new MyButton(Bitmap(button_up.content), Bitmap(button_down.content));
                    addChild(btn);
                    btn.addEventListener(MouseEvent.CLICK, my);
          function my(event:MouseEvent)
               btn.pressed();
And the last main frame of MyButton timeline has: unpressed();
It all works as I want, but I know, that it's a bad solution... especially calling unpressed() from the frame... So maybe someone could give me some advice about writing my own button class?
PS and I'm sorry for my Endlish =)

OK, I got it, thanks )
But for now I'm afraid I have no time to learn it... but I really got it, I think )
That's what I get for now:
package  {
     import flash.display.MovieClip;
    import flash.display.Loader;
    import flash.display.Bitmap;
    import flash.net.URLRequest;
    import flash.display.LoaderInfo;    
    import flash.events.MouseEvent;
    import flash.events.Event;
    public class MyButton extends MovieClip
         public var upStatePath:String;
        public var downStatePath:String;
     public var l:Loader = new Loader();
     var b:Boolean;
        public function MyButton(_upState:String, _downState:String)
          upStatePath = _upState;
          downStatePath = _downState;
          unpressed();
          addEventListener(MouseEvent.CLICK, pressed);
          addFrameScript(totalFrames-1, unpressed)
        public function pressed(event:MouseEvent = null)
          b = true;
          l.contentLoaderInfo.addEventListener(Event.COMPLETE, showPic);
             l.load(new URLRequest(downStatePath));
        public function unpressed()
          b = false;
          l.contentLoaderInfo.addEventListener(Event.COMPLETE, showPic);
                l.load(new URLRequest(upStatePath));
                gotoAndStop(1);
     function showPic(event:Event)
          try {
               removeChildAt(0);
          catch(e:Error) {}
          addChild(Bitmap(l.content));
          if (b) play();
It works as I want, no code in the frames, quite independent I guess ))
That's enough for me for now )
Thanks for help!

Similar Messages

  • Alpha transparency borders on dynamically loaded images for use with textures

    Hi there folks. Well, I have been beating my head over this
    and am hoping one of you can help me out.
    Essentially I have 16bit images that are loaded into my
    shockwave application at run-time. These images are user defined
    which means that I will not know their size ahead of time. Once the
    images are loaded I then create textures and apply them to various
    shaders. Ok, all of this works just fine. What I need to do though
    is create an alpha transparent border around the images, so when I
    apply them to their surfaces I only see the image and nothing
    around it. I am doing this because these images will only appear at
    specific parts on a surface, textureRepeat will be false, and many
    models will be stacked in the same exact location using the same
    model resource. I have everything working, but I cannot figure out
    the alpha part for the life of me. Also, when I test the alpha
    based image by itself it works just fine. It is not until I try and
    combine the 16bit (converted to 32bit at run-time) image that I run
    into problems.
    I have tried:
    - Creating a 32bit alpha image in Fireworks with a
    transparent border and a black rect for the inside. I then copy the
    dynamic image over the alpha image (only after going from 16bit to
    32bit in imaging Lingo) and leave a little room at the edges for
    the transparency. Well, I get a crazy amount of streaks here even
    when I try to up the trans border by around 24 pixels on each side.
    - Using another similiar alpha based image as a mask with
    copyPixels and extractAlpha/setAlpha like this... (code is a little
    rough here)
    newImage = new(#bitmap)
    newImage.name = "place_Test"
    newImage.image = member("place").image
    newAlpha = new(#bitmap)
    newAlpha.name = "AHH"
    newAlpha.image = image(newImage.image.width + 24,
    newImage.image.height + 24, 32)
    newAlpha.image.useAlpha = true
    newAlpha.image.copyPixels(member("vase").image,
    newAlpha.image.rect, member("vase").image.rect)
    newAlphaInfo = newAlpha.image.extractAlpha()
    newAlpha.image.useAlpha = false
    --reverse dark to light
    iAlphaReverse = image(newAlpha.image.width,
    newAlpha.image.height, 8, #grayscale)
    iAlphaReverse.fill(iAlphaReverse.rect, rgb(0,0,0))
    iAlphaReverse.copyPixels(newAlphaInfo, iAlphaReverse.rect,
    newAlphaInfo.rect, [#ink : #reverse])
    --newAlphaInfo.copyPixels(iAlphaReverse, newAlphaInfo.rect,
    iAlphaReverse.rect, [#ink:#subtractpin])
    newAlphaMask = iAlphaReverse.createMask()
    rescaleAbs(newImage, newImage.image.width,
    newImage.image.height, "place_Test", 32)
    destImage = member("place_Test").image.duplicate()
    destImage.fill(destImage.rect, rgb(0,0,0))
    newAlpha.image.useAlpha = false
    destImage.copyPixels(newImage.image, newImage.image.rect,
    newImage.image.rect, [#maskImage:newAlphaMask, #ink:#add])
    destImage.setAlpha(iAlphaReverse)
    destImage.useAlpha = true
    member("place_Test").image = destImage
    I apologize for the messy code. I have cut and pasted from
    all over the place and am getting confused. In any case, I think I
    am making this harder then it needs to be and hope someone can
    help.
    Thank you in advance,
    Dave

    Hi, you can try using other texture layer as mask on the same
    shader. As usually you create the texture from a dynamic loaded
    image, then apply this texture to the shader on the texture list
    index 1 (textureList[1]). Next part does the job, create other
    texture from a 32 bits image with the alpha information and fill
    all pixels with white color, this is very important because the
    second texture layer will be multiply with the first texture layer.
    This texture set its render format to rgba8888. Apply the mask
    texture to the same shader at texture list index 2, verify that the
    blendFunctionList index 2 is #multiply.
    I include the code of a project that use this masking
    approach:
    property pMember
    property pEarthSphere
    property pNightSphere
    property pLastTransform
    on beginSprite me
    pMember = sprite(me.spriteNum).member
    me.setupWorld()
    end
    on setupWorld(me)
    pMember.resetWorld()
    repeat with i = pMember.light.count down to 1
    pMember.deletelight(i)
    end repeat
    vEarthModelResource = pMember.newModelResource("EARTH MODEL
    RESOURCE", #sphere)
    vEarthModelResource.radius = 50.000
    vEarthModelResource.resolution = 20
    vEarthTexture = pMember.newTexture("EARTH TEXTURE",
    #fromCastMember, member(3,1))
    vEarthShader = pMember.newShader("EARTH SHADER", #standard)
    vEarthShader.emissive = color(255,255,255)
    vEarthShader.flat = TRUE
    vEarthShader.transparent = FALSE
    vEarthShader.textureList[1] = vEarthTexture
    pEarthSphere = pMember.newModel("EARTH MODEL",
    vEarthModelResource)
    pEarthSphere.shaderList = vEarthShader
    vNightModelResource = pMember.newModelResource("NIGHT MODEL
    RESOURCE", #sphere)
    vNightModelResource.radius = 50.2000
    vNightModelResource.resolution = 20
    vNightTexture = pMember.newTexture("NIGHT TEXTURE",
    #fromCastMember, member(4,1))
    vNightTexture.quality = #lowFiltered
    vNightTexture.nearFiltering = FALSE
    vNightTexture.renderFormat = #rgba8880
    vNightShader = pMember.newShader("NIGHT SHADER", #standard)
    vNightShader.emissive = color(255,255,255)
    vNightShader.flat = TRUE
    vNightShader.transparent = TRUE
    vNightShader.textureList[1] = vNightTexture
    vMaskNightTexture = pMember.newTexture("MASK NIGHT TEXTURE",
    #fromCastMember, member(6,1))
    vMaskNightTexture.renderFormat = #rgba8888
    vNightShader.textureList[2] = vMaskNightTexture
    vNightShader.textureModeList[2] = #wrapPlanar
    pNightSphere = pMember.newModel("NIGHT MODEL",
    vNightModelResource)
    pNightSphere.shaderList[1] = vNightShader
    pNightSphere.parent = pEarthSphere
    end
    on exitFrame(me)
    pEarthSphere.rotate(0.0,0.1,0.0)
    me.moveMaskNightTexture()
    end
    on moveMaskNightTexture(me)
    vRotationVector = - pEarthSphere.transform.rotation
    pNightSphere.shaderList[1].wrapTransformList[2].rotation =
    vRotationVector
    end

  • Dynamically loading images: UI Loader issue

    I posted this last week, but did not show good examples to get help. Admittedly, I am new to flash, so this may be a bit elementary, so my apologies in advance. I am trying to dynamically load images through the UI Loader component. Attached are the errors I get, and although I think that the coding is close to correct, when I publish, it just flashes up then restarts the movie... any ideas? Thanks in advance.

    there's a problem attaching things to this forum.  so, nothing is attached.
    can you copy and paste your error messages to this forum?

  • How to dynamically load images into Flash

    I have a movie clip on the stage that I want to dynamically
    load images into (that constantly change), how would I go about
    doing this? Thanks.

    Use the Loader class to load in images.
    Then use addChild to add the Loader class into your MovieClip
    on the stage.
    As far as "constantly change" what
    do you mean by that? You could use setInterval, ther enterFrame
    event, or any other means to trigger a new image to be loaded into
    the Loader instance.
    Finally, you can use the Tween class to create some nice
    effects for the images (fade it, blur in, photo blend, masks,
    etc)

  • Dynamically loaded images cached?

    We have an xml feed that is refreshed every hour. According
    to the xml file, we dynamically load an image into an html text
    field each time someone hits our page. All of the images have been
    recently updated, but the old ones are still appearing? We use the
    swf?nocache=randomnumber convention to make sure the swf file
    itself isn't cached, but is there anything we can do to clear out
    the cache of dynamically loaded images? If there isn't anything we
    can do, will these all eventually refresh themselves? This is how
    the html is generated where "twcImage[0]" is the image in question.
    Thanks!

    Do the same random number for the images.
    twcImage[0] + randomnumber
    Dan Smith > adobe community expert
    Flash Helps >
    http://www.smithmediafusion.com/blog/?cat=11
    http://www.dsmith.tv
    "Wolli World" <[email protected]> wrote in
    message
    news:fvvcrc$k9o$[email protected]..
    > We have an xml feed that is refreshed every hour.
    According to the xml
    > file,
    > we dynamically load an image into an html text field
    each time someone
    > hits our
    > page. All of the images have been recently updated, but
    the old ones are
    > still
    > appearing? We use the swf?nocache=randomnumber
    convention to make sure
    > the swf
    > file itself isn't cached, but is there anything we can
    do to clear out the
    > cache of dynamically loaded images? If there isn't
    anything we can do,
    > will
    > these all eventually refresh themselves? This is how the
    html is
    > generated
    > where "twcImage[0]" is the image in question. Thanks!
    >
    > twcTarget.text = "<img align='left' hspace='5'
    vspace='0' src='
    http://" +
    > _root.server + "/rss/weather/images/" +
    > twcImage[0] + "'>" + "<condition>" + ... and so
    on
    >

  • Get width and height of a dynamically loaded image once it's done loading?!

    hello : :
    well... i'm taking my first shots at flex after programming
    in flash for a year now. it's been fun and i've been picking up on
    things pretty well (or so i think), but i come across something
    today that i used to be able to do in my as2 programming and don't
    know how to do in as3...
    in flex, i'm loading an image into an image control (by using
    "myImgControl.load(urlString)"). i have a "complete" parameter on
    the image control that calls a function just fine after the image
    is loaded, but if i try and check the hight and width of the loaded
    image once it loads, it comes back as zero. how can i get the
    height and width of the image after it's loaded?!
    in flash/as2 i used to do this little trick/work-around i
    found in a forum (kirupa.com, i think) to find out the width and
    height once the loaded image listener checked the loading process
    and came back "complete"... in the code below, "imgLoader" is the
    movieClip the image was loaded using
    imgLoaderListener.loadClip(urlString, imgLoader).
    quote:
    iTot = imgLoader.getBytesTotal();
    iLoad = imgLoader.getBytesLoaded();
    if (iLoad == iTot && iTot > 4) {
    imgH = imgLoader._height;
    imgW = imgLoader._width;
    that all make sense?!
    basically, it's as simple as this: i need to find something
    similar to the above for as3 that will tell me the width and height
    of a dynamically loaded image after it's done loading...
    so there ya have it. i appreciate any help any of you can
    throw my way! thank you so much for even reading this!
    : : michael

    I assume you have probably already figured this out, but just
    in case, there should be an event to listen for after which you can
    get the height and width information successfully. I can't remember
    the exact name, however. Experiment and see which one works
    time-wise.

  • Using Firefox to access facebook chat Button or online friiend chat button generates a Black screen with CANNOT LOAD IMAGES and no chat window opens.

    This does not happen in other browsers and it happens on a variety of computers I have access to and would seem to be a common problem but I can find no identical cases in my searches of
    Firefox , Facebook or windows help or Google search. My home machine is only a P2 with WINXPCORP but works fine and I have done all updates but still have this continuing problem every time I try to use Firefox
    to access Facebook chat but it does not happen with IE or chrome
    The response to clicking on chat button or friend chat is a black screen with small center square box with blue title bar that says
    '' VIEW IMAGE FULL SCREEN - (42) FACEBOOK X""
    center of box is ""! "" mark in yellow triangle and wording
    "" CANNOT LOAD IMAGES ''' OK
    clicking on OK returns to facebook page but no chat opens.
    Some times |VERY RARLEY if as the page loades you click on
    chat button with 1/2 second of it appearing chat will open.

    Hi,
    Please also see [https://support.mozilla.org/en-US/kb/Problems%20using%20Facebook%20in%20Firefox this.]

  • Remote debugging an executable with dynamically loaded subpanel VIs

    All,
    A colleague of mine is attempting to perform remote debugging of an executable he has inherited. It includes subpanels that show dynamically loaded VIs. When connecting with the remote debugger, the main executable shows fine, but the dynamically loaded VIs are not showing their front panels. They appear ok on the remote PC where the executable is running, but they don't appear on his laptop from where he is running the debugger.
    I don't have access to LabVIEW currently, and he cannot get this to work, so I thought I'd ask the community this generic question:
    "Is it possible to remotely debug a LabVIEW executable with subpanels that show dynamically loaded subVIs?"
    Technically he can see and probe the block diagram of the main executable, but the subpanels are blank where the dynamcally loaded subVI front panel should show, making it impossible to interact with the program.
    Thoric (CLA, CLED, CTD and LabVIEW Champion)

    Thanks Josh. Does this issue have a CAR number I can tag?
    Thoric (CLA, CLED, CTD and LabVIEW Champion)

  • Problems with Dynamically Loaded jpgs

    Hello all,
    I'm trying to create a dynamic flash slideshow that loads
    external jpgs (and thus can be reused). I can get my jpgs to load
    just fine but when I try to center the loaded images I run into
    problems.
    Here is my code for reference:
    quote:
    _root.createEmptyMovieClip("parentClip", 1);
    parentClip.createEmptyMovieClip("containerClip", 1);
    parentClip.containerClip.loadMovie("images/tempSlideshowImages/image2.jpg");
    When I go to get the width or height of parentClip (or
    containerClip for that matter) I get 0 no matter what I do, even
    though the image is loaded and displays just fine.
    Is there any way to load a jpg into a movie clip and then
    manipulate the movieclip normally?

    Use the MovieClipLoader class, and then use its onLoadInit
    callback to set
    your properties once the clip is available to manipulate.
    Dave -
    Adobe Community Expert
    www.blurredistinction.com
    http://www.adobe.com/communities/experts/

  • How do you size dynamically loaded images?

    Hi,
    I am loading images from mysql into flash using php, I need
    to make thumbnails out of these images, so they need to be resized
    as they are loaded in and then displayed to one set size. Does
    anyone have any ideas?
    thanks
    Gavin

    Jan-Paul K>
    i thought it was _xscale & _yscale?
    thahip>
    if what you need is "one set size", then use _width &
    _height.

  • Sizing Dynamically loaded images

    I've loaded images into a project at runtime they show, but
    when I try to resize them they are set as a percentage of the
    original size and not the pixel size. I've tried using setProperty
    and object._width= and object._height=. Every place I've read
    anything about the _width and _height properties says it should set
    those values in pixels, but for some reason it's percentage for me.
    I'm loading .jpg images
    have flash 8 pro
    How can I set the picture width and height in pixels?

    you need to ensure that the picture is loaded(preferably
    using MovieClipLoader.onLoadInit) before resizing.

  • Dynamically loading images?One at a time :(

    codeworld....help...sos.....send in more troops....the titanic is sinking.....
    The problem:
    I am trying to load dynamic images in order without all of them attempting to load at once....
    I have an array of images that I loop through depending on the gallery that will load up....but when i loop through the images all of them try to load.
    What i need to happen is somewhere in the loop i guess....each image fully load....then goto the next image and fully load.....etc.....
    Basically each image load one at a time in order......and the list is dynamic so uhhhhh HELP ......????
    save narnia....save tinseltown.....awww hell sacrifice yo self and just save me .....

    ok ok......one of these i'm going to make work
    ....thanx for all the help....
    this is kinda the basics of how i got the method looking that i will change
    for(var i=0; i<listArray.length; i++)
                   //picListLoader is a custom class......its just the loaded picture and some variables attached to it.....
                    var picture:picListLoader = new picListLoader(pID, ptitle, pdesc, picURL, i );
                    picArray.push(picture);
                    addChild(picture);
    i think instead of calling the class to create the individual objects......
    i'm going to create a gallery object......and send in the info....and once all of the picture's urls and info is loaded into the object tell the gallery object to load each one of the pictures using one of the methods above......and that should cure my ills
    smallville was saved once again................byMe... ...selfGlory..... .......(ok....saved by yall) thx a million
    thelegendaryghost

  • How To Dynamically Load Images in Crystal Reports?

    Post Author: philips
    CA Forum: General
    What I want is to have image files saved on a local drive and the images to be loaded into a picute/image frame based on a certain condition - same way it's (easily) done with VB.Net or ASP.Net image objects.
    Can you help?

    Not in Crystal Reports Basic for Visual Studio 2008. You'll have to upgrade to CR 2008 (12.x). Then use kbase [1320507|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do] as a guide on how to do this.
    Ludek

  • Problem with dynamically loading the dropdown list from database

    Please help me,
    i am having a jsp page which contains a form
    with a textfield ,two dropdown list
    and a submit button
    when i select a list from first drop down, second drop down has to
    be loaded from the database dynamically according to the
    selected one in the first drop down.
    i gave onselect event for the first drop down and
    gave this one
    temp=first dropdown selected value
    self.location='currentfile+query='+temp;
    after this current page is reloading, but the already existing
    values in textfield and first selected value in drop down list is
    missing.
    how to solve this problem? and the rest of the problem. i mean
    loading the data into second drop down list.
    plz help me......

    in first <selcet> tag write Onchange and submit to the jsp then the values will return in second select box.

  • What is the BEST way to do a dynamically loading image slideshow?

    Hey guys!
    I know a little Flash, a little Dreamweaver, a little PHP,
    pretty much a little of everything. I'm an artist and would like to
    publish a slideshow, which I would update often, smack on the front
    of my personal website. What is the easiest, most painless, least
    complicated, and most easy to update way to do it? And why? I've
    found a lot of tutorials and posts on this, but which do you think,
    as a matter of opinion, would be the best?
    If anyone could link to tutorials especially, that would be
    FANTASTIC.
    Thank you!
    Alecc

    On Wed, 9 Aug 2006 08:30:15 +0000 (UTC), "letsjumpnow"
    <[email protected]> wrote:
    > I know a little Flash, a little Dreamweaver, a little
    PHP, pretty much a
    >little of everything. I'm an artist and would like to
    publish a slideshow,
    >which I would update often, smack on the front of my
    personal website. What is
    >the easiest, most painless, least complicated, and most
    easy to update way to
    >do it? And why? I've found a lot of tutorials and posts
    on this, but which do
    >you think, as a matter of opinion, would be the best?
    See
    http://www.slideshowpro.net/product_ssp.php
    It will be the best $20 you ever spent. It displays images
    based on an
    XML file, which you can generate dynamically with PHP. All
    you'd need to
    do then would be to upload a new image and it could
    automatically be
    added to the show.
    Gary

Maybe you are looking for

  • Problem in recovering a database on another machine

    Dear All, I need your help in restoring and recovering a database on another machine. I don't have access to old machine to get logfile or archivelogs. I have taken full backup using RMAN. I have restored the database using rman sucessfully and tryin

  • Certain playlists are in reverse order

    Dear All, All of my music on my iPhone has sync'ed properly, but in one play list titled "Purchased", all the songs are listed from oldest to newest, even though in my iTunes database, they are sorted by most recent purchases first. Other than manual

  • Experiencing frequent kernel panic

    I have a G4 AGP with 1.4 Ghz Sonnet processor upgrade (original 400 MHZ) and a flashed ATI Radeon 9200 card. I am also using a 4 port USB2 PCI card and a couple USB Hubs. Over the last couple of the weeks I am getting a daily kernel panic (usually wh

  • Is my macbook already protected from viruses?

    does my macbook come equipted with a virus fire wall or some type of protection?

  • Sync - iPhoto

    I cannot sync photos saved on iPad to my laptop - iPhoto does not open up when I connect my iPad - only iTunes. When I open up iPhoto - my iPad does not appear in the side bar as a device to import from.