Explanation of addChild and removeChild?

Hi
I'm having trouble getting my head around using removeChild.
For example, I have a function that is triggered by a button click.  This function loads an external swf.  I then set a global variable swfLoaded to true, with the idea of having an if condition that executes removeChild(loader) if swfLoaded is true.
When trying to execute removeChild(loader), I get an error telling me that it must be the child of the caller.
I've seen the code below, which loads a default swf, but I don't want a default swf - I just want one loaded if the button is clicked, and then if another button is clicked, the original one to be removed before the next swf is loaded.
Can someone please explain to me why removeChild(loader) only works if addChild(loader) was originally executed outside of the function (like below)?
How do I make this code work without loading a default swf, just loading one once someone clicks a button, and then removing it?
var Xpos:Number = 110;
var Ypos:Number = 180;
var swf:MovieClip;
var loader:Loader = new Loader();
var defaultSWF:URLRequest = new URLRequest("swfs/eyesClosed.swf");
loader.load(defaultSWF);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
// Btns Universal function
function btnClick(event:MouseEvent):void {
removeChild(loader);
var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
loader.load(newSWFRequest);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);
// Btn listeners
eyesClosed.addEventListener(MouseEvent.CLICK, btnClick);
stingray.addEventListener(MouseEvent.CLICK, btnClick);
demon.addEventListener(MouseEvent.CLICK, btnClick);
strongman.addEventListener(MouseEvent.CLICK, btnClick);
Cheers
Shaun

Oh, I just did not pay enough attention to your code.
The way you wrote it - you don' have to remove it every time. A better approach is to add it only once and in subsequent calls to unload it:
var loader:Loader = new Loader();
// add it once
addChild(loader);
function btnClick(event:MouseEvent):void {
     // don't need this
     //removeChild(loader);
     // unload previously loaded content
     loader.unload();
     var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
     loader.load(newSWFRequest);
     loader.x = Xpos;
     loader.y = Ypos;
     // don't need this either
     // addChild(loader);
Also, in Flash 10 it is better to use loader.unloadAndStop()

Similar Messages

  • AddChild and removeChild with MouseEvent

    Hello, I am a newby at AS3. I need help with addChild and removeChild.
    I want to make a two buttons one addChild and other removeChild . Friend helped me a little bit, but I didnt uderstand the script ;]
    Here is the example script which my friend gave to me. In other words I want to make a button that attached hair and the other that removes.
    Should I make a separete custom class for Hair? And if do, can someone help? :]
    ActionScript Code:
    public function changeHairs (newHair: Hair): Hair
    Face.removeChild (oldHairs);
    oldHairs = newHair;
    Face.addChild (newHair);
    newHair return;
    Or modify this code. I know how to change text, but dont know how to change objects
    ActionScript Code:
    package  {
        import flash.display.MovieClip;
        import Button;
        import flash.text.TextField;
        import flash.events.MouseEvent;
        public class Faces2 extends MovieClip
            public var arr:Array = new Array("a1","a2","a3");
            trace("aab");
            public var txt:TextField = new TextField()
            public var btnBack:Button = new Button();
            public var btnFwd:Button = new Button();
            public var arrPos:Number = 0;
            public function Faces2()
                setupInterface();
                setupData(arrPos);
            public function setupInterface():void
                btnBack.x = 100; btnBack.y = 10;
                btnFwd.x = 200; btnFwd.y = 10;
                btnBack.addEventListener(MouseEvent.CLICK, back);
                btnFwd.addEventListener(MouseEvent.CLICK, fwd);
                addChild(btnBack);
                addChild(btnFwd);
                txt.textColor = 0xFF0000;
                txt.width = 300;
                txt.border = true;
                txt.x = 100; txt.y = 100;
                addChild(txt)
            public function fwd(evt:MouseEvent):void
                arrPos ++;
                if(arrPos >= arr.length)
                    arrPos = 0;
                setupData(arrPos);
            public function back(evt:MouseEvent):void
                arrPos --;
                if(arrPos < 0)
                    arrPos = arr.length - 1;
                setupData(arrPos);
            public function setupData(pos:Number):void
                txt.text = arr[pos];
    P.S. sorry for my bad english

    did you create your hair movieclip and assign it a class?

  • Action script 3 question: addChild and removeChild on same button??

    I'm trying to make a button that when u click once, the movieclip will be removed and second time back on stage and so forth....
    somehow i get this error
    ==================================
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display:DisplayObjectContainer/removeChild()
    at sample_fla::MainTimeline/btnClick()
    ==================================
    Anyone can help me with this, since I'm doing an interactive web for client and the deadline is near..... thanks in advance.
    these are my code:
    stop();
    var swf:MovieClip;
    var loader:Loader= new Loader();
    var defaultswf:URLRequest= new URLRequest("./newSwfImport.swf");
    //default swf when loaded
    loader.load(defaultswf);
    //add to stage
    allSwfLoadHere.addChild(loader);
    var boolean:Boolean = true ;
    function btnClick(event:MouseEvent):void {
    if(boolean == true){
    allSwfLoadHere.removeChild(loader);
    boolean == false
    if(boolean ==false){
    allSwfLoadHere.addChild(loader);
    boolean == true
    newSwfImport.addEventListener(MouseEvent.CLICK,btnClick);

    you have, at least, two errors:
    1.  you failed to use an if-else and
    2.  when trying to re-assign your boolean, you tested.  ie, you used == when you should use =.  so, your boolean remains true.  then when you execute the 2nd time, you try and remove something that's already been removed.
    use:
    var swf:MovieClip;
    var loader:Loader= new Loader();
    var defaultswf:URLRequest= new URLRequest("./newSwfImport.swf");
    //default swf when loaded
    loader.load(defaultswf);
    //add to stage
    allSwfLoadHere.addChild(loader);
    var boolean:Boolean = true ;
    function btnClick(event:MouseEvent):void {
    if(boolean){
    allSwfLoadHere.removeChild(loader);
    } else {
    allSwfLoadHere.addChild(loader);
    boolean=!boolean;
    newSwfImport.addEventListener(MouseEvent.CLICK,btnClick);

  • Loading .swf, addChild, and removeChild

    Hello all,
    I'm trying load an swf when you click a button, and load another in it's place when you click a different button.   I'm using addChild to insert the swf onto the stage.  Problem is that every time I click a new button, the new swf is loaded on top of the previous one, and I need the previous one to disappear.  I tried using the removeChild method before the new swf is loaded to no effect.
    Here's the function I'm using for the loader with my removeChild attempt in bold:
    function newPage():void {
        trace("load activated");
        trace(""+target+".swf");
        var req:URLRequest=new URLRequest(""+target+""+".swf");
        var loader:Loader = new Loader();
       if (loaderState==true){
            top_mc.removeChild(loader);
        loader.load(req);
        loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, preLoad);
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
        function preLoad(event:ProgressEvent):void {
            var percent:Number=Math.round(event.bytesLoaded/event.bytesTotal*100);
            top_mc.preload_txt.text=String(""+percent+"");
        function fileLoaded(event:Event):void {
            trace("file loaded");
            top_mc.addChild(loader);
            loaderState=true;
    The error I get is as follows:
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
        at flash.display::DisplayObjectContainer/removeChild()
        at main_fla::MainTimeline/newPage()
        at main_fla::MainTimeline/workLoaderEnter()
        at main_fla::MainTimeline/clickF()
    Perhaps there is a way to give the addChild an instance name so that I can remove it later?
    Any ideas?
    Thanks!

    Part of the problem is your trying to remove the loader just after you define it...  it is not a child of anything at that point.  Try the following instead of what you have.   Another problem you can avoid is to not nest functions...
    var loader:Loader
    var loaderState:Boolean = false;
    function newPage():void {
    if (loaderState){
            top_mc.removeChild(loader);
        var req:URLRequest=new URLRequest(""+target+""+".swf");
        loader = new Loader();
        loader.load(req);
        loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, preLoad);
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
    function preLoad(event:ProgressEvent):void {
        var percent:Number=Math.round(event.bytesLoaded/event.bytesTotal*100);
        top_mc.preload_txt.text=String(""+percent+"");
    function fileLoaded(event:Event):void {
        top_mc.addChild(loader);
        loaderState=true;

  • AddChild and removeChild (AS 3)

    Hi
    If I load an external swf (located in the same dir as the one
    loading it) with addChild. It looks something like this
    var url:String = "patfinder_extra1.swf";
    var urlReq:URLRequest = new URLRequest(url);
    ldr.load(urlReq);
    addChild(ldr);
    Now, I want to be able to close/remove this new child within
    itself, image a little close button with the label "I'm a child and
    will close my self if i click here!".
    Now, this removeChild is a mystery and the new restrictions
    in paths in AS 3 really makes it hard. To simply use
    this.removeChild() returns errors.
    Any tips of how to close this thingy?
    :)

    you can use the code below to have the child movieclip remove
    itself from its parent's display list, but that won't clear it for
    garbage collection.
    i would have the child call a function in the parent that
    removes it and nulls all references to its loader so it can be
    garage collected.

  • Outlook to iPhone sync failure – Sync suddenly stopped working for calendar events but continued for contacts and notes.   Finally Fixed!!!  SUPPORT TEAM – PLEASE SEE THIS – Complete explanation of cause and correction steps.

    The issue:  Outlook to iPhone sync failure – Sync suddenly stopped working for calendar events but continued for contacts and notes.   Finally Fixed!!! 
    SUPPORT TEAM – PLEASE SEE THIS – Complete explanation of cause and correction steps.
    The cause:  It is now clear what caused this problem.  For years I had several “all-day” events in my Outlook calendar (birthdays, anniversaries, etc.).  In May 2012 I decided to make some of them one hour  events so I could add alerts to remind me of the event.  I did this by dragging them in Outlook to the time I wanted and expanding them to the time slot desired and then adding the alarm.
    The symptom:  Syncing stopped working for the calendar but continued working for contacts and notes.  I didn’t realize sync was failing until months later when I missed two very important phone calls, so when I noticed it the cause was not obvious. 
    The failed attempts:  I’m head of a software firm and my calendar sync is a crucial to my business life so I took this on with a vengeance.  From a quick look at events in Outlook and the iPhone I could see that the problem started in May 2012.  Events before May were in both Outlook and the iPhone but events after May were only one or the other.  Unfortunately I had changed several other things at the same time relating to other events so again the cause was not obvious.  MANY calls with AppleCare proved them incompetent so my internal IT guys assisted trying many things.  We tried a huge number of calendar changes and several versions of iTunes, iPhone OS and Office as well as both iPhone 4 and 5, all without success.
    The fix:  After 18 months of frustration, MANY  hundreds of $ expense and MANY hours of wasted time I saw a blog that had a calendar sync  problem and it indicated all day events were related.  I changed the display of the Outlook calendar to the list view, added columns so I could see “all day” event check marks as well as times of events,  sorted on the “all day” event column to move them to the top, and for all events that were “all day” events AND had a start and end time, I removed recurrence and then added the annual recurrence back…
    After I fixed all events that had BOTH “all day” set and had a start/end time, I tried another sync.  It synced for the first time in 18 months! 
    Problem occurred May 2012 – fixed Nov 2013

    Hi, to remove dummy '_ModGrp' entries, rather than crashing the 'Suppr' key on your keyboard, you can use this basic VBA macro (launched for instance from Excel).
    It will recursively remove all '_ModGrp...' folders
    Sub RemoveFolders_Click()
        Dim oOutlook As Outlook.Application
        Set oOutlook = New Outlook.Application
        Set objNameSpace = oOutlook.GetNamespace("MAPI")
        Call CleanFolders(objNameSpace.Folders)
    End Sub
    Sub CleanFolders(objFolders As Outlook.Folders)
        For i = objFolders.Count To 1 Step -1
            If Left(objFolders(i).Name, 7) = "_ModGrp" Then
                objFolders.Remove( i )
            Else
                If Not objFolders(i).Folders Is Nothing Then
                    Call CleanFolders(objFolders(i).Folders)
                End If
            End If
        Next i
    End Sub

  • Why redeeming a code is so complicated? We need valid reason and explanation to get and satisfied on what we paid for. Make things easy, not messy.

    Why redeeming a code is so complicated? We need valid reason and explanation to get and satisfied on what we paid for. Be user-friendly to make it easy not messy.

    I did that link you refer to me (manually and using camera). But still nothing happens, always prompted "not properly activated" or "invalid code". And i did follow the instructions how to send an issue/problems/case regarding itunes card code query.
    My apology dude.
    I did change country/region, itunes store country, apple id, but still prompting FAILURE "The Gift Certificate or Prepaid Card you entered has not been properly activated." Does it mean it needs to activate by Apple Inc. before i can use it? If that's the case, everytime i buy an itunes card, i need to go Apple Support? Is that so?
    Please help me dude regarding this matter, i know you're well knowledgeable about apple systems.
    Thanks in advance.

  • Difference between addChild and internal movieclip

    Hi all,
    What is the difference bettween addChild and the movieclip which is in the movieclip.
    we can get those instance from getChildAt() but
    as per the internal movieclip we can get instance from "mc.mcInternal".
    But when i addChild in "mc" we unable to get that instance from this method "mc.mcInternal".
    what is the diffecenct between addChild and internal movieclip.
    Thanks in Advance
    flashgeeks.

    When you create child movieclips inside a parent movieclip, Flash Pro automatically declares member variables for them, so you can access them by "mc.mcInternal". If you add child to a movieclip at runtime, member variables are no longer declared automatically.
    You either declare member variable yourself (public var myMc:MovieClip;) or you can always access it by myParentMc.getChildByName("myChildMcName");
    Otherwise, there's no difference between the two. Only one more thing to keep in mind: If you put movieclip into another movieclip, you control its z-orderby its layer. When you add child by addChild() method, children are put into "depths", not layers anymore. The lowest depth is just above the highest layer. If you want to addChild() to a specific layer, you have to create an empty movieClip (a holder) in Flash Pro, put it in desired layer and then call myHolder.addChild(childMc).

  • Problem with addChild() and getChildAt()

    Can someone tell me why the last trace outputs undefined?
    var myMC1:MovieClip = new MovieClip();
    var myMC2:MovieClip = new MovieClip();
    myMC1.addChild(myMC2);
    myMC1.getChildAt(0).name = "myMC3";
    trace(myMC1.getChildAt(0)); // outputs [object MovieClip]
    trace(myMC1.getChildAt(0).name); //outputs myMC3
    trace(myMC1.myMC3); // outputs undefined

    quote:
    Originally posted by:
    smohadjer
    So if I understand you correctly if I add a movie clip to
    another movie clip using addChild() it would not be the same and I
    won't be able to use the dot syntax to refer to the second movie
    clip. But why?
    This is because when you use addChild you add it to
    DisplayContainer display list - not as a property of the parent
    movie. Dot notation is for reading or invoking something that is in
    the scope of an object. By adding a display object to display list
    - it doesn't add another property to the Object's scope. Again, as
    Ned said there are way to read the content of display list. In
    order for the syntax you are craving for to work you need to create
    properties and methods explicitly. Most of the classes in the
    flash.display package are not dynamic (you cannot add more than
    they already provide - you need to extend them in order to do
    that),
    This is the way it is. I hear what you are saying though (and
    must admit that, perhaps, it looks more intuitive to refer to
    children via dot notation) but from the viewpoint of OOP and AS3
    architecture it would not be correct. I do see a good reason for
    Adobe decoupling display list from object's properties. But this is
    too long a discussion.

  • Error #2025: addChaild and removeChild

    hello all
    I have the app but I got a problem
    ArgumentError: Error # 2025: The supplied DisplayObject must be a child of the caller.
    at flash.display :: DisplayObjectContainer / removeChild ()
    at xxxxx_fla :: MainTimeline / hitPoint ()
    my code
    import flash.events.Event;
    import flash.events.MouseEvent;
    var pencilta:Shape = new Shape();
    var activeColor:uint = 0x000000;
    var aaa:a = new a();
    aaa.x = 0;
    aaa.y = 0;
    addChild(aaa);
    var bbb:c1 = new c1();
    bbb.x = 308;
    bbb.y = 108;
    addChild(bbb);
    var ccc:c2 =new c2();
    ccc.x = 265;
    ccc.y = 175;
    addChild(ccc);
    var ddd:c2 = new c2();
    ddd.x = 235;
    ddd.y = 260;
    var eee:c2 =new c2();
    eee.x = 200;
    eee.y = 355;
    bbb.addEventListener(MouseEvent.MOUSE_DOWN, hta1drag);
    bbb.addEventListener(MouseEvent.MOUSE_UP, hta1drop);
    bbb.addEventListener(Event.ENTER_FRAME, hitPoint);
    function drawingta()
              addChild(pencilta);
              pencilta.graphics.lineStyle(10, activeColor);
    function drawPencilta(e:MouseEvent):void
              pencilta.graphics.lineTo(bbb.x, bbb.y);
              e.updateAfterEvent();
    function hta1drag(e:MouseEvent):void
              e.target.startDrag();
              pencilta.graphics.moveTo(bbb.x, bbb.y);
              stage.addEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);
              drawingta();
    function hta1drop(e:MouseEvent):void
              stopDrag();
              stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);
    function hitPoint(e:Event)
              if(bbb.hitTestPoint(ccc.x,ccc.y, true))
                        removeChild(ccc);
                        addChild(ddd);
              else if (bbb.hitTestPoint(ddd.x,ddd.y,true))
                        removeChild(ddd);
                        addChild(eee);
              else
                        trace ('mbuh lah');
    thank's

    use:
    import flash.events.Event;
    import flash.events.MouseEvent;
    var pencilta:Shape = new Shape();
    var activeColor:uint = 0x000000;
    var aaa:a = new a();
    aaa.x = 0;
    aaa.y = 0;
    addChild(aaa);
    var bbb:c1 = new c1();
    bbb.x = 308;
    bbb.y = 108;
    addChild(bbb);
    var ccc:c2 =new c2();
    ccc.x = 265;
    ccc.y = 175;
    addChild(ccc);
    var ddd:c2 = new c2();
    ddd.x = 235;
    ddd.y = 260;
    var eee:c2 =new c2();
    eee.x = 200;
    eee.y = 355;
    bbb.addEventListener(MouseEvent.MOUSE_DOWN, hta1drag);
    bbb.addEventListener(MouseEvent.MOUSE_UP, hta1drop);
    bbb.addEventListener(Event.ENTER_FRAME, hitPoint);
    function drawingta()
              addChild(pencilta);
              pencilta.graphics.lineStyle(10, activeColor);
    function drawPencilta(e:MouseEvent):void
              pencilta.graphics.lineTo(bbb.x, bbb.y);
              e.updateAfterEvent();
    function hta1drag(e:MouseEvent):void
              e.target.startDrag();
              pencilta.graphics.moveTo(bbb.x, bbb.y);
              stage.addEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);
              drawingta();
    function hta1drop(e:MouseEvent):void
              stopDrag();
              stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);
    function hitPoint(e:Event)
              if(bbb.hitTestPoint(ccc.x,ccc.y, true))
    if(ccc.stage){
                        ccc.parent.removeChild(ccc);
    // ccc=null; ??
                        addChild(ddd);
              else if (bbb.hitTestPoint(ddd.x,ddd.y,true))
    if(ddd.stage){
                        ddd.parent.removeChild(ddd);
    // ddd = null; ??
                        addChild(eee);
              else
                        trace ('mbuh lah');
    thank's

  • MovieClip, addChild and Position

    Hi!! I'm having a problem with a MovieClip...
    I have 2 different MovieClips... that I'm putting into another MC (mc3)..... the new MC's position is x=0 y=0.... I assume this is default....
    what I'm trying to do is change the position of my MC.... but I want the other 2 movies inside (mc and mc2) to be on x=0 and y=0 inside the new movieclip....
    I hope it's not too confusing.... I'm doing this because I'm trying to save the movie as a jpg.... and the only way i can see the file complete is when I set the size of all the stage (1024 x 768).... I only want to save the mc3....
    here's my code.... hope you can help me
    var mc3:MovieClip=new MovieClip();
    addChild(mc3)
    mc3.addChild(mc)
    mc3.addChild(mc2)
    mc3.x=292;
    mc3.y=126;
    //this is what's happening when i save the file

    Thanks but no, that's not doing anything.... it's moving the contents....
    what I'm doing is a game of drag and drop, where children can choose an undefined number of houses and buildings, and arrange them over a city... that's done.... the background and houses are inside mc and the buidings are inside mc2.... I'm working  like that 'cause I must be able to erase everything on each step of the way... erase houses.... then erase buildings..... finally, when everything is over, I have to be able to save the map with the houses and buildings as a jpg file... and also I have to be able to print the map..... that's why I put both mcs inside a new one (mc3) to deal with only one movieclip............  the print part is going fine.... but I can't make the jpg to be just the map.... in order to see the map complete I have to save the file with a size of 1024 x 768... and the idea is to save a jpg with just the map......
    so I was wondering if there is a way to change the position of the movieclips inside my new movieclip.... or any other way I can fix this....
    thanks!!!

  • Where can I find an explanation of Processes and Log files for LMS 3.2?

    Being fairly new to Ciscoworks, I've been scouting for documentation that explains the processes as enumerated by the "pdshow" command. Also, when there are problems, I find myself hunting through the log files without a clear understanding of which log file most likely contains the data I need for troubleshooting purposes.
    Is there a document, preferably in table format, that has at least a brief explanation of each of these items? I can probably eventually glean this information from reading all of the documentation, but that would be a lengthy task.
    Thanks in advance.

    Hi John,
    Kindly refer to below doc by Joseph Clarke which have detailed explanation for all the daemons of CiscoWorks .
    https://supportforums.cisco.com/docs/DOC-8798
    Hope it helps.
    Thanks,
    Gaganjeet

  • Explanation  of MB01 and generation of Goods Recipt

    Hello Experts,
              This is my first exposure to BDC , i am totally clueless, and in need of some urgent help.
      Can someone be kind enough to explain, How  TC:MB01 works in a BDC program where Goods recipts are generated based on the Purchase Order.
      Thanks & Regards,
         Goldie.

    Hi!
    To understand, how BDC is working, you can create a recording for the transaction MB01.
    For this, use SM35, then click on recording.
    Create a recording about MB01.
    Then create a program from your recording.
    Regards
    Tamá

  • Explanation on ARCH and LGWR during recovery stage

    Hi there,
    I've set my Data Guard and it works in "real time". However, the during the real time apply it's slow getting data on the online redo log from the primary. But, it's very quick when apply the archive log files to the standby.
    If I do a simple insert on a table TEST1 with one record on the primary database. Noted the TEST1 table has one column with NUMBER datatype ( insert into TEST1 values (1);). It will takes more than 20 seconds before I see the data on the standby when I apply real time. Noted, I didn't do a log switch (alter system switch logfile).
    However, when I insert thousand of records on the primary and do a log switch. I see the data right away on the standby.
    This really doesn't make sense to me. I know the LGWR write to the primary and standby and I know the ARCH process will archive the redo log when a manual switch or the log is full. But my test only has 1 record on the online redo log. Why does it takes so long to apply on the standby when the archived log has 20 meg apply much quicker?
    Thanks

    can you post log_archive_dest_<n> reading 'service= ...'
    for the primary database?
    Sybrand Bakker
    Senior Oracle DBA

  • HTML5 Canvas: addChild and position

    Hey Guys
    I have an item on the stage called 'square1', I have added a symbol from the library and given it the name 'circle1'.
    I wish to position circle1 at the exact location of square1, my question is - how would I go about doing that?
    Thanks

    Knowing JavaScript is going to be essential for you to use Canvas. If you really don't want to get your hands into the code you should do your best with the timeline.
    If you're ready to take the canvas plunge then JavaScript has to become a tool for you. The second page of what I linked would show you that for almost every bit of ActionScript you might be used to, there's a translation over to JavaScript that's necessary. So every time you go to do something you're going to be right back here.
    The best option just might be for you to take a look at EaselJS. There's lots of very simple demos that can get you started with HTML5/Canvas and will give you answers you want in Flash. Take a look:
    CreateJS | A suite of Javascript libraries and tools designed for working with HTML5

Maybe you are looking for