Drawing with ActionScript3.0(Sprite) in Flash CS4

Hi,
I wanted to make a scene, similar to a little game.
I included:
A character with an Instance Name "character_mc"
A box1 with an Instance Name "hp_mc" (hp for health points)
And a second box2 with an Instance Name "dmg_mc" (dmg for damage)
Now I used this code to make it draw a health bar for me:
     var hp:Number = 100 //note this is not the complete code just the piece I want to focus on
this.addEventListener(Event.ENTER_FRAME, hpBar);
function hpBar(event:Event):void{
     if(character_mc.hitTestObject(hp_mc)){
          hp+=1
     }else if(character_mc.hitTestObject(dmg_mc)){
          hp-=1
     var bar:Sprite = new Sprite();
     bar.graphics.beginFill(0x33ff00);
     bar.graphics.drawRect(50, 50, hp, 15)
     bar.graphics.endFill();
     addChild(bar);
It draws me 100 pixel health, and when the character moves on the box1(hp_mc)
I can see the health increasing (more and more pixels are drawn)
The problem starts here.
When I move my character onto the box2(dmg_mc). It does subtract and eventually draw in the negative, but it does not erase what was drawn before.
How can I code this to have the same function but erases the previous drawing?
Any seggestions are wellcome.
~Thanks for help and advice ~

I believe you are looking for the clear() function.  Note, I also moved the bar variable declaration out of the function so that you don't reinitialize it unnecessarily, as well as the addChild so you only add the bar to the stage once.
var hp:Number = 100 //note this is not the complete code just the piece I want to focus on
var bar:Sprite = new Sprite();
addChild(bar);
this.addEventListener(Event.ENTER_FRAME, hpBar);
function hpBar(event:Event):void{
     if(character_mc.hitTestObject(hp_mc)){
          hp+=1
     }else if(character_mc.hitTestObject(dmg_mc)){
          hp-=1
     bar.graphics.clear();//
     bar.graphics.beginFill(0x33ff00);
     bar.graphics.drawRect(50, 50, hp, 15)
     bar.graphics.endFill();

Similar Messages

  • Drawing with a graphics tablet in Flash

    Hey community!
    I recently got the newest version of Flash and wanted to do some drawing with my graphics tablet, but whenever i try to draw a freehand line, using the pencil or paintbrush tool, then for some reason, it draws a straight line leading to the bottom left side of the screen, and i have no idea why it is doing this.
    When i use the tablet to draw in Photoshop, then it works absolutely fine, but not in Flash
    Any help will be lovely!!
    Thank you

    Hi,
    The issue is resolved in the latest update of Flash Pro.Please update Flash professional to 14.1.0.96 .Follow the instruction below for the same :
    Installation instructions
    Log out and log in to the CC desktop application. Update the application when prompted.
    You should see the list of new updates as soon as the new CC desktop application is launched.
    Install Flash Professional CC and Mobile Device Packaging app. On a high speed connection, it took me around 8 minutes.
    After the application is installed, you can launch the application directly from the desktop app by clicking on it.
    Thanks & Regards,
    Sangeeta

  • Problem with the bone tool in FLash CS4

    I cannot get this bone to connect with the lower part of the leg. I am doing a standard rough draft character walking. please help me
    p.s. if you have a vid or solution please post it in the topic ^_^
    http://www.youtube.com/watch?v=TX8lDhbT7ig
    I posted it and if there is any problem it is in the attachment 

    HI Fuzzles128
    Would you mind sending your file to us? I would like to investigate this issue.
    [email protected]
    Please include info on your OS and the Flash version number (you can find it in About Window -- the number starting from 11. ). Also, please include STEPS to reproduce this bug.
    Sandy
    QE
    Flash Authoring

  • When drawing with the shape tool in Flash how can I vary the stroke width?

    I created an oval shape and I'd like to vary the stroke width so it's not all just one uniform thickness. However in the Properties window I can only find the uniform stroke width and style options (solid, dotted, hashed, etc...). How can I add some tapering?
    Thank you for your help.
    Sarah

    You probably need to convert the line to a fill and then change the shape of it. .. Modify -> Shape -> Convert Lines to Fills

  • Basic Flash CS4 Dilemma 0_o

    Hi all,
    I am wondering why I can create shapes with the fill and stroke I specify only in templates and not when I select a new action script 3.0 or any of the other types of flash documents. Does anyone have a link to information on this or can explain what I need to configure?
    Looking across the Internet, I have not seen anything on this. 0_o

    Hi Ganesh,
    Thank you for the reply. I know how to draw and make motion tweens in Flash CS4 after I select the templates upon opening a new document:
    New
    Template
    My problem is being able to draw anything with a filled in shape in another of the other types of Flash documents. When I draw a shape or import a button it has a strange green hue or just a green outline. The only way I can get all of the functionality is to use the templates but these have limited sizes...
    Is there something I have not configured? I do not know if I am describing this in enough detail. I should probably provide a screencast. : /

  • FLASH CS4 freezing Windows Vista

    I had similar problems with livecycle and acrobat with it
    being slow and freezing (even though it was never as bad as Flash
    CS4 is) but when I try to open Flash CS4 it takes FOREVER to open
    and usually it doesn't open and freeze. When it does open (after I
    have to wait 5 mins minimum) it usually freezes in the program.
    With Acrobat, I moved the preferences folder and it helped resolve
    my problem and I replaced some file with livecycle so I am assuming
    there is a similar fix with possibly replacing some potential flash
    cs4 settings or file? This is killing me and I can't use my
    computer for Flash so I would deeply appreciate the help if anyone
    can see what ways I can resolve this issue that I have been having
    for quite some time now!

    hopefully someone can help..

  • Help with Illustrator CS6 and Flash CS4

    Hello I use Illustrator CS6 and Flash CS4. When I export a drawing realized in Illustrator in the size(format) .sof Flash, this one is imported in the library(bookcase) of Flash CS4 but he(it) is created with a multitude of graphic symbols and symbols Bipmap. In the scene(stage) of Flash, the image is illegible it is floutée, apparently it is not a vectorial image. Thank you for your answer. Very cordially.
    Thank You !!!

    Sometimes a picture is better than a description. I had to use a translator to find out that floutee means blurred.
    Generally bitmaps (raster images) are not a strong suite for illustrator. It can do some things with them, just not as much as photoshop. Maybe if you could explain what you want to do with the symbol, then maybe we can give some ideas. Also by posting a screen shot, we might know of where there is a vector alternative.

  • Cannot draw a transparent rectangle in Flash CS4

    Hi,
    In Flash CS4, when I draw a rectangle (or circle, or anything) with a color that has 0 alpha, nothing is drawn. Also, if I select a piece of drawing and change the color to 0 alpha, the drawing (e.g. rectangle) disappears!!
    Is there any way to disable this astonishingly stupid behaviour?
    I know I can draw a non-transparent rectangle, convert it to movie clip and set the movie clip's alpha to 0, but I'd like to avoid this.

    No it isn't a feature. It is definitely a bug. I experienced this once before. I had the part where if I selected something that already existed and changed its fill to alpha 0 then it just disappeared. And I too thought it was somebody had made a really bad programming choice when writing CS4.
    But then it went away. I've never figured out what caused it or why. I think at the time my response was just to set the alpha low (1%) with a thought like, "Well, that is hella annoying, I don't have time to deal with it now I'll come back and figure it out later." And then it just got better on its own.
    Sorry I don't have anything specific other than to tell you that you aren't alone and you aren't imagining it!
    You have updated to 10.0.2? I can't remember if it happened to me before the update or not. Are you on a Mac or PC? I also can't remember if this happened to me at work or home, so I don't know which one I saw it on. BTW I just tried it on my Mac and I can draw and/or change a shape to fill alpha zero.

  • Hello, I have a problem with Adobe flash cs4 Professional, the tool, : Trace Bitmap

    So anyways, I was trying to make a Sprite animation using Adobe Flash Cs4 Professional. And While someone gave instructions on how to do so on Youtube, it said to use the Trace Bitmap tool in the top where tools are listed. So when I click, a downloading bar pops, and its loading so it can load it and do whatever the Trace Bitmap tool does. So anyways, when its like half-and-a-quarter done, one quarter stopped downloading, and to exit Adobe Flash Cs4 Professional, I have to activate Task Manager, and the tool dosen't work, help please.

    Did the Flash plugin crashes also happen with a previous version (10.1) of the Flash player?
    If you have submitted Breakpad crash reports then post the IDs of one or more Breakpad crash reports (bp-xxxxxxxx-xxxxxxxxx-xxxx-xxxxxxxxxxxx).<br />
    You can find the IDs of the submitted crash reports on the <i>about:crashes</i> page.<br />
    You can open the <b>about:crashes</b> page via the location bar, like you open a website.
    See:
    * http://kb.mozillazine.org/Breakpad (Mozilla Crash Reporter)

  • Is Flash CS4 not compatible with Intel Graphics (laptop)? Really?

    Hi!
    I'm graphic and animation designer. My company buys CS4 suite
    including Photoshop & Flash. And I'm buying a laptop and now
    choosing between one having Intel Graphics and another with ATI
    Radeon. Intel has some features I need, but after googling, finding
    and reading this topic:
    http://www.adobeforums.com/webx?14@@.59b6c473/0
    till the end, I see it does not fully support Photoshop
    CS4!!! I also need Flash CS4 working, so does it support Flash?
    So can you still recommend me buying intel integrated-laptop
    or should I take an ATI Radeon powered one? I need Flash working
    without annoying compatibilites problems. I don't want to buy an
    Intel one, if it is not Photoshop- and Flash- compatible....
    Thank you!

    Anne,
    > after googling, finding and reading this topic:
    >
    http://www.adobeforums.com/webx?14@@.59b6c473/0
    > till the end, I see it [an Intel chip] does not fully
    support
    > Photoshop CS4!!! I also need Flash CS4 working, so does
    > it support Flash?
    It's important you understand what "fully support" means in
    this
    context. According to Eric Palmer's Dec 4 reply (12:11pm),
    Photoshop CS4
    does, in fact, run reliably on systems with Intel graphics.
    Eric purports
    to be an Intel employee, but obviously there's no proof of
    that.
    Regardless, his assertion jibes with with I hear from
    colleagues with Intel
    graphics chips.
    It's not as if Photoshop suddenly fails if you happen to
    choose, say,
    red from the color swatches. It's not as if Photoshop fails
    to export GIFs
    on Intel machines. The only thing you're missing -- and this
    is true for me
    too, even though I don't have Intel equipment -- is
    functionality that
    relies on OpenGL. One of these features, for example, lets
    you rotate the
    canvas while you work on a file. I don't mean rotate the
    image itself ... I
    mean rotate the actual work space without resampling the
    image, just as if
    you were rotating the piece of paper on which you were
    drawing. Granted,
    that sounds like a neat feature (I'd like to experiment with
    it, myself!),
    but it's not a deal-breaker.
    As far as I've seen, the Flash CS4 authoring tool doesn't
    rely on any
    OpenGL-accelerated features.
    David Stiller
    Adobe Community Expert
    Dev blog,
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • 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
    >

  • Error in creating XML photo gallery with Flash CS4 and AS 3.0

    Hello, all. I've been creating an XML photo gallery with Flash CS4 and AS 3.0 following a tutorial. I followed the instructions step-by-step but at the end I got the following error message instead:
    Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
    Could anyone in the community assist me as to how to solve the problem? The script has no errors and last time I checked all the applicable files (the .xml file, the .jpg files, the .swf and the .fla file) are in my Documents folder on the Mac.
    Looking forward to your suggestions!

    Check the folder structure
    Flash is not able to get some file thats why the IO Error.
    trace the url path just before u load the file and u will be abel to find whether that file is in specified folder or not.
    http://www.darshanrane.com

  • Flash CS4 not working with Windows 7 64bit and Kaspersky Internet Security

    I have a new i5 core computer running Windows 7 64bit retail. With Kaspersky Internet Security 2010 installed Flash CS4 becomes so unresponsive that it is completely unusable. Uninstall KIS and it works absolutely fine. I've already read on another forum that someone else is experiencing the same issue with the same combination of products. Is anyone else having this problem amd if so how did you solve it? I've posted on the Kaspersky forum with no solution thus far.
    Does Norton work OK with Windows 7(64) and CS4?

    *** PROBLEM SOLVED ***
    Taxxem you are a star. Ideed turning off 'disable external service control' and disabling 'self defense' under 'settings  -options' does indeed bring Flash back to life. Disabling self-defense had the most impact (and causes Kaspersky to grumble somewhat) but disabling external service control also had an impact, albeit much smaller. I'll post this solution against my Kaspersky forum post and hopefully they will do something about it.

  • Problem with symbols while exporting a gif in flash cs4

    I am using flash cs4 to export a simple animated gif for a button on my website. However, when I export the gif the movie symbols will not play, what am I doing wrong here?

    Well, for some reason, I've managed to be okay with the idea that all software relying on links is prone to crushing at any given moment during execution of a project, Yes this includes After effects, Illustrator, Indesign_name it. However, one thing I cannot understand or even come to terms with the idea that Flash CS4 cannot export a project of 162mb. My library is organised, My scenes are in perfect order,  I do not even use 3rd party componets in my projects..... but for some reason, I cannot export let alone publish an application file from FLASH CS4.
    My first thought was maybe some thing was wrong with the "flash.ocx" extension, so I took a walk and visited the Adobe site to get an update, but still after re-installing it nothing seems to put a smile on my face_( I've spent sleepless nights on this animation and all I need is to just export/ publish it, however flash exports it halfway and out of a blue the export dialog and the incomplete file vanish) Some times I  even wonder wether there is a vortex on my desktop.
    Another problem in this category am finding is with flash player in my browsers, if it runs in exlporer, then it won't run in firefox, and when I check in the control panel after installing on both browsers, I am so suprised to find 4plugins of flash player, which is not the case with my friends laptops which use 1plugin and an activeX control for the web browsers.
    Any help is very welcome, Am using Dell studio-xps Laptop running a 64bit  Windows Vista OS, 4bg Ram, 1 Terabyte HDD and yes Intel Graphics media card with dedicated memory of 1gb. (Of what use are they if I cannot export a small file of 162mb, am even ashamed to mention it, heeeeeelp  )

  • In Flash CS4 a generated html with swf file won't play swf

    Using Flash CS4 and having the Flash plug-in ver 10 on my PC, the generated html file will not play the swf in the browser.
    I noticed that the active-x javascript is now included in the header as well as the javascript portion in the body tag.
    But it won't play.  I get the typical blank window in IE with the "X" in the upper left corner.
    I don't have this problem with Flash CS3.
    Any ideas what may be going on?
    Thank you.

    I am having similar difficulty; mostly I am confused.
    I want to open a flash video file in a frame within a webpage.
    I have generated a Flash CS4 html and swf file. When loaded they play, but they play on a separate, full size web page, not in the frame where I want it.
    I then generated FLV and F4V files but that doesn't work.
    It appears that I need to insert the object and embed tags "for Flash Movies" in the html file.
    Once I do that, do I go back to only putting in the html and swf files and create a link to the html file to bring up the video in the target frame?
    What are the FLV files for?

Maybe you are looking for