Note that there are some explanatory texts on larger screens.

plurals
  1. POmoving between states I get an error in Flex
    text
    copied!<pre><code>ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. </code></pre> <p>so i have a function that runs in state1 and has a </p> <pre><code>while(myCanvas.rawChildren.numChildren &gt; 0){ myCanvas.rawChildren.removeChildAt(0); } //this code is definitely the problem.... </code></pre> <p>I can move to state2, but when I move back to state1 i get the error.</p> <p>why? the function that has the while loop only runs when something is searched in state1, so why is it running when coming back from state2?</p> <p>edit... </p> <p>so i did i test for a function that runs at app initialization:</p> <pre><code>private function init():void{ trace(g); if(g == true){ while(myCanvas.rawChildren.numChildren &gt; 0){ myCanvas.rawChildren.removeChildAt(0); } g = false; } trace(g); } </code></pre> <p>It shouldnt run one it comes back to state1, but i still get the error. So basically as long as that while loop runs once while in state1 I can never get back to state1</p> <pre><code>&lt;mx:states&gt; &lt;mx:State name="contactform"&gt; &lt;mx:AddChild position="lastChild"&gt; &lt;mx:Canvas id="msgCanvas" backgroundColor="0xEEEEEE" height="121" y="158" width="800" fontWeight="normal" fontSize="12" backgroundAlpha="0.02" x="0"&gt; &lt;/mx:Canvas&gt; &lt;/mx:AddChild&gt; &lt;mx:AddChild position="lastChild"&gt; &lt;custom:email_cmp x="150" y="287" height="213"/&gt; &lt;/mx:AddChild&gt; &lt;/mx:State&gt; &lt;mx:State name="main"&gt; &lt;mx:AddChild position="lastChild"&gt; &lt;mx:Canvas id="myCanvas" backgroundColor="0xEEEEEE" height="342" y="158" width="800" fontWeight="normal" fontSize="12" backgroundAlpha="0.02" x="0"&gt; &lt;/mx:Canvas&gt; &lt;/mx:AddChild&gt; &lt;/mx:State&gt; &lt;/mx:states&gt; public function mainFunction():void{ origArray = []; var cache:int = 0; if(myCanvas.rawChildren.numChildren &gt; 0){ myCanvas.rawChildren.removeChildAt(0); } //text format for links var hFormat:TextFormat = new TextFormat(); hFormat.font = "Verdana"; hFormat.color = 0x000000; hFormat.size = 15; //text format end var sprite1:Sprite = new Sprite(); var textQ:TextField = new TextField(); textQ.mouseEnabled = false; if(amt_cnt.count == 1){ amt_cnt.end = amt_cnt.endCache; amt_cnt.start = amt_cnt.startCache; //set the text textQ.defaultTextFormat = hFormat; textQ.text = "Still can't find your answer? Need more help?"; textQ.x = 270; textQ.y = 300; textQ.width = textQ.textWidth +20; textQ.selectable = false; sprite1.addChild(textQ); sprite1.buttonMode = true; myCanvas.rawChildren.addChild(sprite1); sprite1.addEventListener(MouseEvent.CLICK, moreHelp); }else{ amt_cnt.end = amt_cnt.endCache; amt_cnt.start = amt_cnt.startCache; textQ.defaultTextFormat = hFormat; textQ.text = "More Questions..."; textQ.x = 275; textQ.y = 300; textQ.width = textQ.textWidth +20; textQ.selectable = false; sprite1.addChild(textQ); sprite1.buttonMode = true; myCanvas.rawChildren.addChild(sprite1); sprite1.addEventListener(MouseEvent.CLICK, moreQuestions); } var fontSize:int = 12; //text formatting for the displayed question list Begin var qFormat:TextFormat = new TextFormat(); qFormat.font = "Verdana"; qFormat.color = 0x000000; qFormat.size = fontSize; //ending text format for(var t:uint = amt_cnt.start; t&lt;amt_cnt.end; t++){ /*if(t == 0){ var topQ:TextField = new TextField(); topQ.text = full_array[t][1]; mainQsprite.addChild(topQ); }*/ var qSprite:Sprite = new Sprite(); var txt:TextField = new TextField(); txt.defaultTextFormat = qFormat; txt.text = full_array[t][0]; txt.selectable = false; txt.mouseEnabled = false; txt.border = false; txt.width = 500; // how wide you want the text to go. var numLines:Number = Math.floor(txt.textWidth/txt.width)+1; //calculates number of lines of the textfield. txt.height = ((fontSize+8)*numLines); txt.wordWrap = true; qSprite.x = 30; qSprite.y = 350; qSprite.alpha = 0; var temp_a:Number = cache; //20 is the padding between questions displayed if(t != amt_cnt.end-1){ Tweener.addTween(qSprite, {y:temp_a, alpha:1, time:1, delay:t*0.1, transition:"easeoutexpo"}); //tweener INNNNN! }else{ Tweener.addTween(qSprite, {y:temp_a, alpha:1, time:1, delay:t*0.1, transition:"easeoutexpo", onComplete:runTop}); //tweener INNNNN! } cache = txt.height + temp_a; qSprite.buttonMode = true; origArray[t] = new Array(qSprite.x,temp_a, qSprite); mainDict[qSprite] = new Object(); mainDict[qSprite].question = full_array[t][0]; mainDict[qSprite].answer = full_array[t][1]; mainDict[qSprite].count = full_array[t][2]; mainDict[qSprite].top = full_array[t][3]; mainDict[qSprite].origX = qSprite.x; mainDict[qSprite].origY = temp_a; mainDict[qSprite].id = t; mainDict[qSprite].height = txt.height; amt_cnt[t] = new Object(); amt_cnt[t].hit = false; qSprite.addChild(txt); qSprite.addEventListener(MouseEvent.CLICK, clicked); qSprite.addEventListener(MouseEvent.MOUSE_OVER, over); qSprite.addEventListener(MouseEvent.MOUSE_OUT, out); myCanvas.rawChildren.addChild(qSprite); if(full_array[t][3] == true){ var thereIsTop:Boolean = true; } } amt_cnt.array = origArray; /*if(thereIsTop == true){ topAnswer(); //makes the top answer open first thereIsTop = false; }*/ } </code></pre> <p>So this the mainfunction. The top part has the states. main state is loaded first and has the myCanvas canvas. Everything in mainfunction adds to myCanvas.</p> <p>This is my first time working with flex, so tell me if there is a better way of doing this.Thanks?</p> <p>I really need to get this solved. I've been stressing over this for weeks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload