Re: [Flashcoders] Why doesn't this work addChild removechild

2011-04-23 Thread Paul Andrews

On 22/04/2011 18:35, Steve Abaffy wrote:

Quick update

Function{



Var Mort: MovieClip = new Mort();

Try{

 removeChild(Mort);

}catch(e:Error){

 // Do nothing;

}

addChild(Mort);

}



This function is called multiple times and each time it adds the child Mort,
but I want to remove the one placed there previously, it works if I add the
two lines right after each other as in the previous email but I really need
it work more like this.


As has already been pointed out, your variable name is the same as the 
class name, so I'm not sure why the compiler doesn't throw wobbly.


Never name instance variables beginning with a capital letter.







___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] Why doesn't this work addChild() removeChild()

2011-04-22 Thread Steve Abaffy
Hello,

 

Why doesn't this work??

 

In the same function

Var Mort:movieClip = new Mort();

addChild(Mort);

removeChild(Mort);

I get this error

The supplied DisplayObject must be a child of the caller.

 

 

 

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Why doesn't this work addChild() removeChild()

2011-04-22 Thread Deepanjan Das
Hi Steve,
This is because of timing.

You are trying to remove an object which has not completed its addChild
actions.

Hence its not getting the instance when removing.


Warm Regards
Deepanjan Das
W: http://deepanjandas.wordpress.com
|| Om Manasamarthadata Shri Aniruddhaya Namah
||http://www.manasamarthyadata.com/
*Think of the environment before printing this email
__
*


On Fri, Apr 22, 2011 at 10:47 PM, Steve Abaffy st...@msmarketing.bizwrote:

 Hello,



 Why doesn't this work??



 In the same function

 Var Mort:movieClip = new Mort();

 addChild(Mort);

 removeChild(Mort);

 I get this error

 The supplied DisplayObject must be a child of the caller.







 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Why doesn't this work addChild() removeChild()

2011-04-22 Thread Kerry Thompson
Steve Abaffy wrote:


 Why doesn't this work??

 In the same function

 Var Mort:movieClip = new Mort();

 addChild(Mort);

 removeChild(Mort);

 I get this error

 The supplied DisplayObject must be a child of the caller.


It's likely that Mort hasn't had time to instantiate. Either that, or Mort,
being a local variable, isn't there if you leave the function and call it
again. For example:

public function doMort(add:Boolean):void
{

  var Mort:MovieClip;
  if (add == true)
  {
Mort = new Mort();
addChild(Mort);
  }
  else
  {
removeChild(Mort);
  }
}

Mort only survives while the function is running. He's still on the display
list, but the function doesn't know who Mort is when you call him with
false.

Or, it could be something as simple as using an upper-case Var instead of
var.

Have you looked in the debugger, or with trace statements, to be sure Mort
is being created? If instantiation fails, it won't be a valid MC.

Cordially,

Kerry Thompson
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] Why doesn't this work addChild removechild

2011-04-22 Thread Steve Abaffy
Quick update

Function{

 

Var Mort: MovieClip = new Mort();

Try{

removeChild(Mort);

}catch(e:Error){

// Do nothing;

}

addChild(Mort);

}

 

This function is called multiple times and each time it adds the child Mort,
but I want to remove the one placed there previously, it works if I add the
two lines right after each other as in the previous email but I really need
it work more like this.

 

 

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Why doesn't this work addChild() removeChild()

2011-04-22 Thread Merrill, Jason
A couple of things:

1. Var should be lower-case var.  You probably have it as var in your 
code and your e-mail client capitalized it for you (or you mis-typed), but if 
you want is to trouble-shoot, I would post it as it is in your code.  If it is 
Var in your code, it should throw a compiler error.
2. You are naming your instance name the same as the Class name Mort.  
Instance names are also usually lower case, classes upper case, which helps to 
prevent coding errors like this.
3. You are casting your instance as MovieClip when it is actually Mort.  
Your Mort class may extend MovieClip, but it would be better to cast it as 
Mort.

The following works for me:

import mortsPackage.Mort;

function createAndDestroyMortJustForFun():void
{
var mort:Mort = new Mort();
addChild(mort);
removeChild(mort);
}

createAndDestroyMortJustForFun();


 Jason Merrill
 Instructional Technology Architect
 Bank of America  Global Learning 





___


-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com 
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Steve Abaffy
Sent: Friday, April 22, 2011 1:17 PM
To: 'Flash Coders List'
Subject: [Flashcoders] Why doesn't this work addChild() removeChild()

Hello,

 

Why doesn't this work??

 

In the same function

Var Mort:movieClip = new Mort();

addChild(Mort);

removeChild(Mort);

I get this error

The supplied DisplayObject must be a child of the caller.

 

 

 

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

--
This message w/attachments (message) is intended solely for the use of the 
intended recipient(s) and may contain information that is privileged, 
confidential or proprietary. If you are not an intended recipient, please 
notify the sender, and then please delete and destroy all copies and 
attachments, and be advised that any review or dissemination of, or the taking 
of any action in reliance on, the information contained in or attached to this 
message is prohibited. 
Unless specifically indicated, this message is not an offer to sell or a 
solicitation of any investment products or other financial product or service, 
an official confirmation of any transaction, or an official statement of 
Sender. Subject to applicable law, Sender may intercept, monitor, review and 
retain e-communications (EC) traveling through its networks/systems and may 
produce any such EC to regulators, law enforcement, in litigation and as 
required by law. 
The laws of the country of each sender/recipient may impact the handling of EC, 
and EC may be archived, supervised and produced in countries other than the 
country in which you are located. This message cannot be guaranteed to be 
secure or free of errors or viruses. 

References to Sender are references to any subsidiary of Bank of America 
Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are 
Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a 
Condition to Any Banking Service or Activity * Are Not Insured by Any Federal 
Government Agency. Attachments that are part of this EC may have additional 
important disclosures and disclaimers, which you should read. This message is 
subject to terms available at the following link: 
http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you 
consent to the foregoing.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Why doesn't this work addChild removechild

2011-04-22 Thread Kerry Thompson
Steve Abaffy wrote:

Quick update

 Function{

 Var Mort: MovieClip = new Mort();

 Try{

removeChild(Mort);

 }catch(e:Error){

// Do nothing;

 }

 addChild(Mort);

 }

 This function is called multiple times and each time it adds the child
 Mort,
 but I want to remove the one placed there previously, it works if I add the
 two lines right after each other as in the previous email but I really need
 it work more like this.


You have a scope issue. Mort is a local variable, and is no longer there
when you call it the second time. Try moving it up so it's declared in the
class definition, and instantiated in the function.

You have a couple of other problems, too. You have a variable Mort and a
class Mort. You should really make the variable lower case mort, like Jason
suggested.

Also, if that is your entire function, you have other problems. Every time
you call it, you're creating a new Mort (in the variable declaration--var
Mort:MovieClip = new Mort();). That guarantees you that you won't have the
previously created Mort--you just wiped it out on the first line of the
function.

Work with the debugger, Steve. Set some break points, and look at the state
of the variables, follow the logic flow. You'll find you can solve problems
like this more quickly if you understand what's happening in your code.

Cordially,

Kerry Thompson
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders