removeChild in function

Hey guys, I'm having a problem with my function...

The function is called when a user enters text in the field, and then hit ' shorten it. "

.. .and the function works correctly, but it repeats on top of himself on the stage, and I tried to removeChild (varname); at the beginning of the function, but unfortunately if the function is executed for the first time, it gives me an error that there is no such thing as varname!... stuuuuck.

I could possibly remove all children once said that a user clicks in the text field to enter a new url, but I won't be taking the exit before they reach come again... How do I find this?

I couldn't be doing this right... can help you please?

var urlTEXT:TextField = new TextField();urlText.x = (x location);urlText.y...etcaddChild(urlText);
function APIconnect(evt:Event):void{ //DOES THINGS//urlText.htmlText = "Example text";}

.. .he still added a new when I run the function.

EDIT: I thought about it... My vars were still in another function. so when I moved them to the main function, it worked!

Tags: BlackBerry Developers

Similar Questions

  • Access the function of custom class which is stored in a table?

    Hello guys..,.


    I hope I am making stopper, with the title of the thread, because I'm a bit confused, how do you explain in Word...

    anyway I'll describe what I mean and hope you guys can help out me..,.

    Here I am doing some object of action script..,.

    What about this object that is in the constructor function of this object is as I do to send a parameter of sprite that will act as it's parent..,.

    var anObject:myObject = new myObject (parentSprite);

    and in my main project, I used those object and store in a table after it is added to the scene...

    I store it in a table cause I have to be able to return to the it...

    everything was fine until I have to call the function inside this object which I already stored in a table..,.

    so, how should I call the function in this table object that has stored the object?

    hope that I specify me...

    Thanks in advance guys..,.

    Well, the error is tell you that removeChild() destroy() function in the class Newsticker is having a problem because you try to remove a child does not belong to the parent. How your destroy() function looks like?

  • How to pass the e: MouseEvent to another function?

    How to pass the e: MouseEvent to another function?

    public void onObjectFound(e:MouseEvent):void
    {
    var e = e:MouseEvent;
    e.currentTarget.removeEventListener (MouseEvent.CLICK, onObjectFound);
    var myTween:TweenLite = new TweenMax (e.currentTarget, 1, {scaleX:e.currentTarget.scaleX * 1.5, scaleY:e.currentTarget.scaleY * 1.5, onComplete:deleteObj});})
    function deleteObj (): void
    {
    removeChild (DisplayObject (e.currentTarget));
    deleteObjects (e.currentTarget.name);
    dispatchEvent (new Event (Event.COMPLETE));
    }
    }

    ArgumentError: Error #2025: the supplied DisplayObject must be a child of the caller.
    at flash.display::DisplayObjectContainer/removeChild()
    to Function / com.enachedragos:Load_Objects/onObjectFound/com.enachedragos:deleteObj() [s\Blackcode\Desktop\Android game Project\com\enachedragos\Load_Objects.as:39 C:\User]
    service / http://adobe.com/AS3/2006/builtin: applies ()
    at com.greensock.core::TweenCore/complete() [C:\Users\Blackcode\Desktop\Android game Project\com\greensock\core\TweenCore.as:177]
    at com.greensock::TweenMax/complete() [C:\Users\Blackcode\Desktop\Android game Project\com\greensock\TweenMax.as:779]
    at com.greensock::TweenMax/renderTime() [C:\Users\Blackcode\Desktop\Android game Project\com\greensock\TweenMax.as:761]
    at com.greensock.core::SimpleTimeline/renderTime() [C:\Users\Blackcode\Desktop\Android game Project\com\greensock\core\SimpleTimeline.as:79]
    at com.greensock::TweenLite$/updateAll() [C:\Users\Blackcode\Desktop\Android game Project\com\greensock\TweenLite.as:629]

    never nest named functions.

    You can use:

    public void onObjectFound(e:MouseEvent):void
    {

    e.currentTarget.removeEventListener (MouseEvent.CLICK, onObjectFound);
    var myTween:TweenLite = new TweenMax (e.currentTarget, 1, {scaleX:e.currentTarget.scaleX * 1.5, scaleY:e.currentTarget.scaleY * 1.5, onComplete:deleteObj,onCompleteParams:[e.currentTarget]});})

    }

    function deleteObj(dobj:DisplayObject):void
    {
    dobj.parent.removeChild (dob);
    not sure that what follows is logical
    dispatchEvent (new Event (Event.COMPLETE));
    }

  • Is there a way for actionscript 3 to detect if a cursor value is increasing?

    Hi, I'm trying to get my slider to set the size of an object inside one of my pages, that I'm just wondering if there is a way to do it or if it does not work. my current code is below:

    package 
    {
     import flash.display.MovieClip;
     import flash.events.MouseEvent;
     import fl.controls.Slider;
     import fl.events.SliderEvent;
     import fl.controls.Label;
     import fl.controls.NumericStepper;
     import flash.events.Event;
     public class Main extends MovieClip
      {
       //Variables
       var startPage:StartPage;
       var tutorialPage:TutorialPage;
       var maleSizePage:MaleSizePage;
       var femaleSizePage:FemaleSizePage;
     
       public function Main()
       {
     
        //Pages
        startPage = new StartPage  ;
        tutorialPage = new TutorialPage  ;
        maleSizePage = new MaleSizePage  ;
        femaleSizePage = new FemaleSizePage  ;
     
        addChild(startPage);
     
        //Event Listeners
        startPage.startButton.addEventListener(MouseEvent.CLICK,startButtonClick);
        tutorialPage.continueButton.addEventListener(MouseEvent.CLICK,tutorialContinueButtonClick);
        maleSizePage.heightSlider.addEventListener(SliderEvent.CHANGE,heightSlChange_M);
        maleSizePage.neckSlider.addEventListener(SliderEvent.CHANGE,neckSlChange_M);
        maleSizePage.chestSlider.addEventListener(SliderEvent.CHANGE,chestSlChange_M);
        maleSizePage.waistSlider.addEventListener(SliderEvent.CHANGE,waistSlChange_M);
        maleSizePage.armSlider.addEventListener(SliderEvent.CHANGE,armSlChange_M);
        maleSizePage.legSlider.addEventListener(SliderEvent.CHANGE,legSlChange_M);
        maleSizePage.heightValue.addEventListener(Event.CHANGE,heightVChange_M);
        maleSizePage.neckValue.addEventListener(Event.CHANGE,neckVChange_M);
        maleSizePage.chestValue.addEventListener(Event.CHANGE,chestVChange_M);
        maleSizePage.waistValue.addEventListener(Event.CHANGE,waistVChange_M);
        maleSizePage.armValue.addEventListener(Event.CHANGE,armVChange_M);
        maleSizePage.legValue.addEventListener(Event.CHANGE,legVChange_M);
       }
       
       
     
       function startButtonClick(event:MouseEvent):void
       {
        addChild(tutorialPage);
       }
       function tutorialContinueButtonClick(event:MouseEvent):void
       {
        if (startPage.maleSelection.selected == true)
        {
         addChild(maleSizePage);
         removeChild(startPage);
         removeChild(tutorialPage);
        }
        if (startPage.femaleSelection.selected == true)
        {
         addChild(femaleSizePage);
         removeChild(startPage);
         removeChild(tutorialPage);
        }
       }
     
       function heightSlChange_M(event:SliderEvent):void
       {
        
        maleSizePage.heightValue.value = maleSizePage.heightSlider.value;
        
       }
       function neckSlChange_M(event:SliderEvent):void
       {
     
        maleSizePage.neckValue.value = maleSizePage.neckSlider.value;
     
       }
       function chestSlChange_M(event:SliderEvent):void
       {
     
        maleSizePage.chestValue.value = maleSizePage.chestSlider.value;
     
       }
       function waistSlChange_M(event:SliderEvent):void
       {
     
        maleSizePage.waistValue.value = maleSizePage.waistSlider.value;
       }
       function armSlChange_M(event:SliderEvent):void
       {
     
        maleSizePage.armValue.value = maleSizePage.armSlider.value;
       }
       function legSlChange_M(event:SliderEvent):void
       {
     
        maleSizePage.legValue.value = maleSizePage.legSlider.value;
       }
       function heightVChange_M(e:Event)
       {
        maleSizePage.heightSlider.value = maleSizePage.heightValue.value;
       }
       function neckVChange_M(e:Event)
       {
        maleSizePage.neckSlider.value = maleSizePage.neckValue.value;
       }
       function chestVChange_M(e:Event)
       {
        maleSizePage.chestSlider.value = maleSizePage.chestValue.value;
       }
       function waistVChange_M(e:Event)
       {
        maleSizePage.waistSlider.value = maleSizePage.waistValue.value;
       }
       function armVChange_M(e:Event)
       {
        maleSizePage.armSlider.value = maleSizePage.armValue.value;
       }
       function legVChange_M(e:Event)
       {
        maleSizePage.legSlider.value = maleSizePage.legValue.value;
       }
     
     
      }
    }
    
    

    It looks that you assign the value of the cursor to a variable instead of using it to control the height.  The way you use can only increase the height and only if the value of the slider is > = 65

    The slider should be directly affecting the height setting, as in...

    function heightSlChange_M(event:SliderEvent):void {}

    maleSizePage.maleCharacter.height = maleSizePage.heightSlider.value;

    }

  • How to get a digital stepper and a slider to work together.

    Hello, I'm working on a piece of courses for school and I want to have a page where I have cursors that reflect a digital stepper and vice versa but whenever I have find a tutorial online it keeps send me errors, the most recent being 1172: definition fl.events:NumericStepperEvent could not be found... I hesitate to continue with the rest of the steppers to cause because I'm not sure how to run, but I need to have this section made by Friday. Any help will be much appreciated.

    Thanks Matt

    package 
    {
     import flash.display.MovieClip;
     import flash.events.MouseEvent;
     import fl.controls.Slider;
     import fl.events.SliderEvent;
     import fl.controls.Label;
     import fl.controls.NumericStepper;
     import fl.events.NumericStepperEvent;
     public class Main extends MovieClip
     {
      //Variables
      var startPage:StartPage;
      var tutorialPage:TutorialPage;
      var maleSizePage:MaleSizePage;
      var femaleSizePage:FemaleSizePage;
      public function Main()
      {
       //Pages
       startPage = new StartPage  ;
       tutorialPage = new TutorialPage  ;
       maleSizePage = new MaleSizePage  ;
       femaleSizePage = new FemaleSizePage  ;
       addChild(startPage);
       //Event Listeners
       startPage.startButton.addEventListener(MouseEvent.CLICK,startButtonClick);
       tutorialPage.continueButton.addEventListener(MouseEvent.CLICK,tutorialContinueButtonClick);
       maleSizePage.heightSlider.addEventListener(SliderEvent.CHANGE,heightSlChange_M);
       maleSizePage.neckSlider.addEventListener(SliderEvent.CHANGE,neckSlChange_M);
       maleSizePage.chestSlider.addEventListener(SliderEvent.CHANGE,chestSlChange_M);
       maleSizePage.waistSlider.addEventListener(SliderEvent.CHANGE,waistSlChange_M);
       maleSizePage.armSlider.addEventListener(SliderEvent.CHANGE,armSlChange_M);
       maleSizePage.legSlider.addEventListener(SliderEvent.CHANGE,legSlChange_M);
       maleSizePage.heightValue.addEventListener(NumericStepperEvent.CHANGE,heightVChange_M);   
      }
      
      
      function startButtonClick(event:MouseEvent):void
      {
       addChild(tutorialPage);
      }
      function tutorialContinueButtonClick(event:MouseEvent):void
      {
       if (startPage.maleSelection.selected == true)
       {
        addChild(maleSizePage);
        removeChild(startPage);
        removeChild(tutorialPage);
       }
       if (startPage.femaleSelection.selected == true)
       {
        addChild(femaleSizePage);
        removeChild(startPage);
        removeChild(tutorialPage);
       }
      }
      function heightSlChange_M(event:SliderEvent):void
      {
       maleSizePage.heightValue.value = maleSizePage.heightSlider.value;
      }
      function neckSlChange_M(event:SliderEvent):void
      {
       maleSizePage.neckValue.value = maleSizePage.neckSlider.value;
      }
      function chestSlChange_M(event:SliderEvent):void
      {
       maleSizePage.chestValue.value = maleSizePage.chestSlider.value;
      }
      function waistSlChange_M(event:SliderEvent):void
      {
       maleSizePage.waistValue.value = maleSizePage.waistSlider.value;
      }
      function armSlChange_M(event:SliderEvent):void
      {
       maleSizePage.armValue.value = maleSizePage.armSlider.value;
      }
      function legSlChange_M(event:SliderEvent):void
      {
       maleSizePage.legValue.value = maleSizePage.legSlider.value;
      }
      function heightVChange_M(Event:NumericStepper)
      {
       maleSizePage.heightSlider.value = maleSizePage.heightValue.value;
      }
     }
    }
    
    

    import:

    import flash.events.Event;

  • Help tool tip

    Hello

    I was after a bit of advice on how do I create tooltips.

    I have thumbnails of different colors. When the user hovers over the thumbnail I want a ToolTip appears with the name of the color.

    What is the best way to do it?

    I got the job of the ToolTip - just need a bit of advice on the content of the ToolTip!

    This is my code so far but don't know how to create several ToolTips:

    btn1.addEventListener("mouseOver", mouse_RollOver);
    btn1.addEventListener("mouseOut", mouse_RollOut);
    btn1.addEventListener("mouseMove", mouse_Move);
    
    var tooltip:Tooltip = new Tooltip();
    tooltip.txt.text="colour here";
    tooltip.x=stage.mouseX;
    tooltip.y=stage.mouseY-btn1.height;
    
    function mouse_RollOver(e:MouseEvent):void {
    addChild(tooltip);
    var myTween:Tween=new Tween(tooltip,"alpha",Regular.easeIn,0,1,0.6,true); 
    }
    
    function mouse_RollOut(e:MouseEvent):void {
    removeChild(tooltip);
    } 
    function mouse_Move(e:MouseEvent):void {
    tooltip.x=stage.mouseX;
    tooltip.y=stage.mouseY-btn1.height;
    

    I don't want to repeat this code several times for each button as there is lot of thumbnails - I appreciate any advice or help on this...

    Thank you

    You should do the buttons of all instances of a class that you write your won database.

    They can send an event of the ToolTip, and then on your main timeline (or class of documents or where ever) you can listen for this event. Something like this:

    package {}

    import flash.display.MovieClip;

    import flash.events. *;

    import flash.utils.Timer;

    import flash.events.EventDispatcher;

    SerializableAttribute public class MyButton extends MovieClip {} Dynamics

    public static var defaultDelay:Number = 1000;

    public var tipText:String;

    private var _timer:Timer;

    private var _tipDelay:Number = 0;

    private var _intervalID:Number;

    public void MyButton() {}

    Stop();

    addListeners();

    addEventListener (Event.ADDED_TO_STAGE, init);

    }

    public void init(e:Event) {}

    removeEventListener (Event.ADDED_TO_STAGE, init);

    tipDelay = KPButton.defaultDelay;

    _Timer.addEventListener (TimerEvent.Timer, timerHandler);

    }

    private void addListeners() {}

    buttonMode = true;

    mouseEnabled = true;

    mouseChildren = false;

    If (! hasEventListener (MouseEvent.MOUSE_OVER)) {}

    addEventListener (MouseEvent.MOUSE_OVER, handleOver);

    addEventListener (MouseEvent.MOUSE_OUT, handleOut);

    addEventListener (MouseEvent.MOUSE_DOWN, handlePress);

    addEventListener (MouseEvent.CLICK, handleClick);

    }

    }

    private void removeListeners() {}

    buttonMode = false;

    mouseEnabled = false;

    removeEventListener (MouseEvent.MOUSE_OVER, handleOver);

    removeEventListener (MouseEvent.MOUSE_OUT, handleOut);

    removeEventListener (MouseEvent.MOUSE_DOWN, handlePress);

    removeEventListener (MouseEvent.CLICK, handleClick);

    }

    private void handleOver(e:MouseEvent):void {}

    {if (e.buttonDown)}

    return;

    }

    _Timer.start ();

    }

    private void handleOut(e:MouseEvent):void {}

    _Timer.reset ();

    dispatchEvent (new Event ("hideTip"));

    }

    private void handleClick(e:MouseEvent):void {}

    _Timer.reset ();

    }

    private void handlePress(e:MouseEvent):void {}

    _Timer.reset ();

    dispatchEvent (new Event ("hideTip"));

    }

    private void timerHandler(e:TimerEvent):void {}

    dispatchEvent (new Event ("tooltip"));

    }

    public function set {tipDelay(num:Number):void}

    _tipDelay = num;

    _Timer = new Timer(_tipDelay,1);

    }

    public function get tipDelay (): number {}

    Return _tipDelay;

    }

    }

    }

  • Other questions about drag-and - drop and depth

    Okay, team

    so I know my drag and drop code is probably 'stick' on the mouse event because there is something in front of the object...

    I'm trying to implement the numChildren code in order to bring the object moved forward...

    SO I add this code inside each movable answer...

    addEventListener (MouseEvent.MOUSE_DOWN, changedepth);

    function changedepth(event:MouseEvent):void {}

    this.parent.setchildIndex (this, this.parent.numChildren - 1).

    }

    OK so that part is ok, but my project is quite complex, so now when it goes on the next section or there are children who are have not themselves resets...

    So now I want to put something like that

    addEventListener (MouseEvent.MOUSE_UP, removechild);

    function removechild (event. MouseEvent) {}

    this.parent.removeChild(-1);

    }

    but of course this does not... any ideas?

    Cheers for your help

    Void

    You must assign the MOUSE_UP listener on the stage to make him independent object.  If you need to know which object has been moved then store a reference to it in a variable.

    In addition, the removeChild() method argument should be a DisplayObject, not a number

  • Child parameter must be non-null. Error #2007

    Hello world!

    I'm about to finish my game (A matching game cards) and I encountered a problem.

    The piece of code tha giving me the problem is:

    compare two cards
    If (firstCard.cardface == secondCard.cardface) {}
    var beginTime:int = getTimer();
    addEventListener (Event.ENTER_FRAME, removeMatch);
    function removeMatch(event:Event) {}
    milliseconds spent
    var timePassed:int = getTimer () - beginTime;
    calculate seconds
    var seconds: int = Math.floor (timePassed/1000);
    If (seconds == 1) {}
    remove a match
    removeChild (firstCard);
    removeChild (secondCard);
    Reset selection
    firstCard = null;
    secondCard = null;
    }
    }
    Add points
    gameScore += pointsForMatch;
    showGameScore();
    playSound (theMatchSound);
    cardsLeft-= 2; 2 cards less

    TypeError: Error #2007: Parameter child must be non-null.
        at flash.display::DisplayObjectContainer/removeChild()
        at Function/EasyDifficulty/clickCard/removeMatch()[C:\Users\Adi\Desktop\Playbook\Playbook Match Game\Project\EasyDifficulty.as:132]

    Above is the output error I get when clicking on two cards that are the same.

    What is the problem here... I can't fix perhaps because I worked for hours.

    Thanks in advance.

    The problem is probably due to you using an enterframe event continually calling this function.  You must remove this enterframe listener as soon as it has achieved its objectives, or else he will always try to remove objects that they have already been removed.

    You shouldn't bury this function inside the conditional.

    If the goal of all that is simply adds a slight delay before removing objects, you should consider using setTimeout or Timer class instead of using an enterframe scenario.

  • as3 XML slideshow

    Hello!

    I recently created a slide show using a xml and actionscript 3 files. I everythhing works perfectly EXCEPT that I try to add the slide indicators and cannot understand it. I don't have need of these for use of buttons or anything just llittle points to display the number of slides, and that the slideshow is currently. I tried to add it as a part of the xml list and may not if it works properly! This race as a movie can be hung on the stage? If anyone has any advice, it would be reatly appreciated. I have been researching everwhere and can't get anything to work.

    This code example is with some other improvements and points are too interactive:

    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import fl.transitions.TweenEvent;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    
    var img_speed:Number;
    var img_total:Number;
    var img_images:XMLList;
    
    var dotArray:Array = [];
    var img_success_counter:Number = 0;
    var img_playback_counter:Number = 0;
    
    var img_slideshow:Sprite = new Sprite();
    
    var slides:Array = [];
    var dotsContainer:Sprite = new Sprite();
    var img_preloader:TextField;
    
    // reference to previously displayed slide
    var prevSlides:Array;
    
    var img_timer:Timer;
    var img_prev_tween:Tween;
    
    var img_xml_loader:URLLoader = new URLLoader();
    img_xml_loader.load(new URLRequest("slideshow2.xml"));
    img_xml_loader.addEventListener(Event.COMPLETE, processXML);
    
    next_mc.addEventListener(MouseEvent.CLICK, timerListener);
    prev_mc.addEventListener(MouseEvent.CLICK, goBack);
    
    function processXML(e:Event) :void{
         var img_xml:XML = new XML(e.target.data);
         img_speed = img_xml.@SPEED;
         img_images = img_xml.IMAGE;
         img_total = img_images.length();
         loadImages();
         img_xml_loader.removeEventListener(Event.COMPLETE, processXML);
         img_xml_loader = null;
    }
    
    function loadImages():void {
         prevSlides = [];
         img_preloader = new TextField();
         img_preloader.text="Loading";
         img_preloader.autoSize = TextFieldAutoSize.CENTER;
         img_preloader.textColor = 0x7A7A7A;
         img_preloader.x = (stage.stageWidth - img_preloader.width)/2
         img_preloader.y = (stage.stageHeight - img_preloader.height)/2
         addChild(img_preloader);   
    
         var dotX:Number = 0;
         var slide:Sprite;
         var img_loader:Loader;
    
         var titleFont = new Georgia();
         var titleFormat:TextFormat = new TextFormat();
         titleFormat.size = 18;
         titleFormat.align = TextFormatAlign.CENTER;
         titleFormat.font = titleFont.fontName;
    
         var labelFont = new Verdana();
         var labelFormat:TextFormat = new TextFormat();
         labelFormat.size = 11;
         labelFormat.align = TextFormatAlign.LEFT;
         labelFormat.font = labelFont.fontName;
    
         var img_title:TextField;
         var img_label:TextField
         var dot:Dot;
         for (var i:Number = 0; i < img_total; i++) {
              slide = new Sprite();
              img_loader = new Loader ();
              img_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
              // load must be called AFTER listeners are added
              img_loader.load(new URLRequest (img_images[i].@URL));
    
              img_title = new TextField();
              img_title.defaultTextFormat = titleFormat;
              img_title.embedFonts = true;
              img_title.antiAliasType = AntiAliasType.ADVANCED;
              img_title.text = img_images[i].@TITLE;
              img_title.autoSize = TextFieldAutoSize.LEFT;
              img_title.textColor = 0xFF0000;
              img_title.wordWrap = true;
              img_title.width = 250;
              img_title.x = 385;
              img_title.y = 25;
    
              img_label = new TextField();
              img_label.defaultTextFormat = labelFormat;
              img_label.embedFonts = true;
              img_label.antiAliasType = AntiAliasType.ADVANCED;
              img_label.text = img_images[i].@DESC;
              img_label.autoSize = TextFieldAutoSize.CENTER;
              img_label.textColor = 0x7A7A7A;
              img_label.wordWrap = true;
              img_label.width = 215;
              img_label.x = 410;
              img_label.y = 55;
    
              slide.addChild(img_loader);
              slide.addChild(img_title);
              slide.addChild(img_label);
              slide.name = "slide_" + i;
              slide.addEventListener(MouseEvent.MOUSE_DOWN, gotoURL);
              slides.push(slide);
    
              dot = new Dot();
              dot.useHandCursor = dot.buttonMode = true;
              dot.addEventListener(MouseEvent.CLICK, onDotClick);
              dot.alpha = .5;
              dot.x = dotX;
              dot.index = i;
              dotX += (dot.width + 10);
              dotsContainer.addChild(dot);
              dotArray.push(dot);
         }
         dotArray[0].alpha = 1;
         dotsContainer.x = 425;
         dotsContainer.y = 208;
    
         addChild(dotsContainer);
    }
    
    function onComplete(e:Event):void {
         img_success_counter++;
         if (img_success_counter == img_total){
              startShow();
              removeChild(img_preloader);
         }
    }
    
    function onDotClick(e:MouseEvent):void {
         img_playback_counter = e.currentTarget.index;
         nextImage();
    }
    
    function startShow():void {
         addChild(img_slideshow);
         img_timer = new Timer(img_speed * 1000);
         img_timer.addEventListener(TimerEvent.TIMER, timerListener);
         img_timer.start();
         nextImage();
    }
    
    function nextImage():void {
         img_timer.reset();
         img_timer.start();
         setDots();
         for (var i:int = 0; i < img_slideshow.numChildren; i++) {
              prevSlides.push(img_slideshow.getChildAt(i));
         }
         hidePrev();
         img_slideshow.addChild(slides[img_playback_counter]);
         new Tween(slides[img_playback_counter], "alpha", Strong.easeOut, 0, 1, 1, true);
    }
    
    function timerListener (e:Event):void {
         img_playback_counter++;
         if (img_playback_counter == img_total) {
              img_playback_counter = 0;
         }
         nextImage();
    }
    
    function goBack(e:MouseEvent):void {
         img_playback_counter--;
         if (img_playback_counter < 0) {
              img_playback_counter = img_total - 1;
         }
         nextImage();
    }
    
    function hidePrev():void {
         var img_prev_tween:Tween;
         for each(var s:Sprite in prevSlides) {
              img_prev_tween = new Tween(s, "alpha", Strong.easeOut, 1, 0, 1, true);
              img_prev_tween.addEventListener(TweenEvent.MOTION_FINISH, onFadeOut);
         }
    }
    
    function onFadeOut(e:TweenEvent):void {
         while (img_slideshow.numChildren > 1) {
              img_slideshow.removeChildAt(0);
              prevSlides.splice(0, 1);
         }
         e.target.removeEventListener(TweenEvent.MOTION_FINISH, onFadeOut);
    }
    
    function setDots():void {
         for each(var dot:Sprite in dotArray) {
              dot.alpha = .5;
         }
         dotArray[img_playback_counter].alpha = 1;
    }
    
    function gotoURL(e:Event):void {
         navigateToURL(new URLRequest(img_images[img_playback_counter].@LINK));
    }
    
  • for dysfunction of the loop

    I made this small AS3 practice thing, where you can shoot [with a spaceship] on 'enemies' and get extra points.

    I wanted to make a function that enemy respawns after hitting them.

    I have the spawning enemies using a loop for.

    I also remove the enemies when they are hit.

    the problem now is: for some strange reason, the game keeps spawning enemies and ignoring the loop for...


    all variables are defined at the beginning of the script, so I won't include this part:

    These are loops that make enemies spawn

    for (var teller1 = 0; teller1 < 8; teller1 ++) {}
    addvijand1 (null);
    }
    for (var teller2 = 0; teller2 < 8; teller2 ++) {}
    addvijand2 (null);
    }


    adding the addlisteners

    stage.addEventListener (Event.ENTER_FRAME, drainage); irrelevant for now: it's controls
    stage.addEventListener (Event.ENTER_FRAME, schieten); It's the addchild for balls, with included hittest which removes the movieclip of the ball and the enemy and should lessen bij teller1 and teller2 one.
    stage.addEventListener (Event.ENTER_FRAME, addvijand2); addition of the enemies of type 1
    stage.addEventListener (Event.ENTER_FRAME, addvijand1); addition of the enemies of type 2 //this is basically the same [just forms and colors] type 1 in the code, so I'm not going to include to make it easier to forget.


    function addvijand2 {(evt:Event)}
    var vijand2: MovieClip = new MovieClip();
    vijanden2.push (vijand2);
    vijand2. Graphics.beginFill (0x22FF00);
    vijand2. Graphics.drawCircle (-5, 10, 10);
    vijand2.x = (Math.random () * 260) + 20;
    vijand2.y = (Math.random () * 200) + 10;
    var glow2:GlowFilter = new GlowFilter();
    glow2. Color = 0x22FF00;
    glow2.Alpha = 1;
    glow2.blurX = 20;
    glow2.blury = 20;
    glow2. Quality = BitmapFilterQuality.HIGH;
    vijand2.filters = [glow2];
    addChild (vijand2);
    }

    function schieten (evt:Event) {}
    If {(spaceKeyDown)
    var mc: MovieClip = new MovieClip();
    mc.graphics.beginFill (0xFFCC00);
    mc.graphics.drawCircle (3,3,3);
    var glow: GlowFilter = new GlowFilter();
    Glow.Color = 0xFFCC00;
    Glow.Alpha = 1;
    glow.blurX = 10;
    glow.blurY = 10;
    Glow.Quality = BitmapFilterQuality.HIGH;
    MC.filters = [glow];
    MC.x = mc_schip.x;
    MC.y = mc_schip.y;
    mc.addEventListener (Event.ENTER_FRAME, moving);
    addChild (mc);
    }
    }


    function moving (evt:Event) {}
    evt. Target.y-= 20;
    for (var teller1:int = 0; teller1 < vijanden1.length; teller1 ++) {//here it searches if the ball hits an enemy of the table, deletes it if necessary.

    If ((vijanden1[teller1]!=null) & & (evt.target.hitTestObject (vijanden1 [teller1]))) {}
    MovieClip(vijanden1[teller1]).removeEventListener (Event.ENTER_FRAME, vijand1animatie);
    removeChild (vijanden1 [teller1]);
    Score += 2;
    scoretext. Text = "Note:" + score;
    vijanden1 [teller1] = null;
    teller1 +=-1;
    }
    }
    for (var teller2:int = 0; teller2 < vijanden2.length; teller2 ++) {}
    If ((vijanden2[teller2]!=null) & & (evt.target.hitTestObject (vijanden2 [teller2]))) {}


    removeChild (MovieClip (vijanden2 [teller2]));
    score += 10;
    scoretext. Text = "Note:" + score;
    vijanden2 [teller2] = null;
    teller2 +=-1;
    }
    }
    If (evt. Target.y < 0) {}
    MovieClip (evt.target) .removeEventListener (Event.ENTER_FRAME, moving);
    removeChild (MovieClip (evt.target));
    }
    }

    I think that the error is with the stage.addEventListener (Event.ENTER_FRAME, addvijand...);  part, because it is an ENTER_FRAME event, so he adds enemies of each image.

    But even when I move the loops in the functions of addvijand1/2, or change them, while loops, it still does not work...

    What I am doing wrong?

    Since I have nothing better to do here is a more dynamic version with more features. Now enemies explode, and the ship can be moved with the arrow keys left and right. In addition, it eliminates the need for both enemy who makes hit faster detection:

    stop();
    import flash.display.Graphics;
    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.filters.GlowFilter;
    import flash.geom.ColorTransform;
    import flash.geom.Transform;
    // reusable instances
    var enemy:MovieClip;
    var bullet:MovieClip;
    // abstract Gprahics
    var g:Graphics;
    // ship speed
    var shipSx:Number = 3;
    // enemy types data
    var enemyTypes:Object = {      enemy1: {color: 0x00CCFF, shape: "circle", radius: 10, speed: 2, score: 2},
                                       enemy2: {color: 0x22FF00, shape: "rectangle", side: 20, speed: 1, score: 10}
                                  }
    var enemies:Array = [];
    // loop iterator
    var i:int = 0;
    var score:Number = 0;
    //these are the for loops that make the enemies spawn
    makeEnemies();
    
    stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownHandler);
    stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUpHandler);
    
    function makeEnemies():void {
         for(i = 0; i < 8; i++) {
              enemies.push(makeEnemy("enemy1"));
              enemies.push(makeEnemy("enemy2"));
         }
    }
    
    function onKeyDownHandler(e:KeyboardEvent):void {
         switch(e.keyCode) {
              case 32:
                   addEventListener (Event.ENTER_FRAME, schieten);
              break;
    
              case 39:
              case 37:
                   // set ship move direction
                   mc_schip.dx = e.keyCode == 39 ? 1 : -1;
                   mc_schip.addEventListener (Event.ENTER_FRAME, shipMove);
              break;
         }
    
    }
    
    function shipMove(e:Event):void
    {
         mc_schip.x += shipSx * mc_schip.dx;
    }
    
    function onKeyUpHandler(e:KeyboardEvent):void {
         switch(e.keyCode) {
              case 32:
                   removeEventListener (Event.ENTER_FRAME, schieten);
              break;
    
              case 39:
              case 37:
                   mc_schip.removeEventListener (Event.ENTER_FRAME, shipMove);
              break;
         }
    }
    
    function makeEnemy(type:String):MovieClip {
         var data:Object = enemyTypes[type];
         enemy = new MovieClip();
         g = enemy.graphics;
         g.beginFill(data.color);
         switch(data.shape) {
              case "circle":
                   g.drawCircle(0, 0, data.radius);
              break;
    
              case "rectangle":
                   g.drawRect( -data.side * .5, -data.side * .5, data.side, data.side);
              break;
         }
         g.endFill();
         // add data to the object for further use
         enemy.data = data;
         placeEnemy(enemy);
         enemy.isAlive = true;
         enemy.filters = [glowFilter(data.color)];
         enemy.addEventListener(Event.ENTER_FRAME, enemyMove);
         return enemy;
    }
    
    function enemyMove(e:Event):void
    {
         enemy = MovieClip(e.target);
         enemy.y += enemy.data.speed;
         if(enemy.y > (stage.stageHeight + 10)) placeEnemy(enemy);
    }
    
    function placeEnemy(enemy:MovieClip):void {
         enemy.x = Math.random() * stage.stageWidth;
         enemy.y = Math.random() * -100;
         addChild(enemy);
    }
    
    function schieten(e:Event):void {
         bullet = new MovieClip();
         bullet.graphics.beginFill(0xFFCC00);
         bullet.graphics.drawCircle(0, 3, 3);
         bullet.filters = [glowFilter(0xFFCC00, 10)];
         bullet.x = mc_schip.x;
         bullet.y = mc_schip.y;
         bullet.addEventListener(Event.ENTER_FRAME, moveBullet);
         addChild(bullet);
    }
    
    function moveBullet(e:Event):void {
         bullet = MovieClip(e.target);
         bullet.y -= 20;
         bewegen(bullet);
         if (bullet.y < 0) {
              bullet.removeEventListener(Event.ENTER_FRAME, moveBullet);
              if (contains(bullet)) removeChild(bullet);
         }
    }
    
    function bewegen(bullet:MovieClip):void {
         // for each loop is faster
         for each(enemy in enemies) {
              if (bullet.hitTestObject(enemy)) {
                   // allows any bullet to die in exlosion
                   // although only first hit adjusts score
                   if (enemy.isAlive) {
                        enemy.isAlive = false;
                        enemy.addEventListener(Event.ENTER_FRAME, explode);
                        var trans:ColorTransform = new ColorTransform();
                        trans.color = 0xFFB895;
                        enemy.transform.colorTransform = trans;
                        score += enemy.data.score;
                   }
                   // bullet is used only once
                   removeChild(bullet);
                   bullet.removeEventListener(Event.ENTER_FRAME, moveBullet);
                   bullet = null;
                   // exit loop
                   break;
              }
         }
         scoretext.text = "Score: " + score;
    }
    
    function explode(e:Event):void {
         var eo:MovieClip = MovieClip(e.target);
         eo.alpha -= .3;
         eo.scaleY += .5;
         eo.scaleX += .5;
         if (eo.alpha <= 0) {
              // retuen to original state
              eo.isAlive = true;
              eo.transform.colorTransform =  new ColorTransform();
              eo.removeEventListener(Event.ENTER_FRAME, explode);
              placeEnemy(eo);
              eo.alpha = eo.scaleY = eo.scaleX = 1;
         }
    }
    
    function glowFilter(color:uint = 0x00CCFF, blur:Number = 20):GlowFilter {
         var f:GlowFilter = new GlowFilter();
         f.color = color;
         f.alpha = 1;
         f.blurX = blur;
         f.blurY = blur;
         f.quality = BitmapFilterQuality.HIGH;
         return f;
    }
    
  • PREVIOUS FLV Playback button works only once...

    Hi all..

    I have a FLVPlayer who plays a video and once the video is finished playing, is the BACK button. When you click the REPLAY button the movie again... Everything works fine, except the REPLAY button does work once... sense, once the film played only once and BACK button is cilcked to play again, after that the film is done playing for the 2nd time - the button does not appear... Fact, anyone has an idea on why it's perhaps? any help would be great appreciated. Thanks advance! Here is the code:

    Fl.video import. *;
    import flash.display.MovieClip;

    var myVideo:FLVPlayback = new FLVPlayback();
    var mybtn:myBtn = new myBtn();
    var staticpic:staticPic = new staticPic();
    logo: Logo of var = new Logo();

    myVideo.source = "BatterypoweredFCM.f4v";
    myVideo.skin = "SkinOverPlaySeekStop.swf";
    myVideo.skinAutoHide = true;
    myVideo.skinBackgroundColor = 000.
    myVideo.skinBackgroundAlpha =. 5;
    myVideo.width = 960;
    myVideo.height = 540;

    DropShadow
    function init() {}
    var dropShadow:DropShadowFilter = new DropShadowFilter();
    dropShadow.distance = 4;
    dropShadow.angle = 90;
    dropShadow.color = 000.
    dropShadow.alpha =.5
    dropShadow.blurX = 10;
    dropShadow.blurY = 8;

    logo.filters = new Array (dropShadow);
    }

    mybtn.x = 515;
    mybtn.y = 259;
    mybtn.Alpha =. 8;

    staticpic.x = 480;
    staticpic.y = 270;
    staticpic.Alpha =. 4;

    logo.x = 37;
    logo.y = 11;

    myVideo.addEventListener (VideoEvent.COMPLETE, completePlay);
    mybtn.addEventListener (MouseEvent.MOUSE_UP, proofreading);

    function completePlay(e:VideoEvent):void {}
    addChild (mybtn);
    addChildAt(staticpic,0);
    removeChild (myVideo);
    }

    function replay(e:MouseEvent):void {}
    addChildAt(myVideo,0);
    myVideo.play ();
    mybtn. Visible = false;
    staticpic. Visible = false;
    }

    addChildAt(myVideo,0);
    addChildAt (logo, 1);

    init();

    because you do not visible mybtn and you're never change that.  use:

    Fl.video import. *;

    import flash.display.MovieClip;

    var myVideo:FLVPlayback = new FLVPlayback();

    var mybtn:myBtn = new myBtn();

    var staticpic:staticPic = new staticPic();

    logo: Logo of var = new Logo();

    myVideo.source = "BatterypoweredFCM.f4v";

    myVideo.skin = "SkinOverPlaySeekStop.swf";

    myVideo.skinAutoHide = true;

    myVideo.skinBackgroundColor = 000.

    myVideo.skinBackgroundAlpha =. 5;

    myVideo.width = 960;

    myVideo.height = 540;

    DropShadow

    function init() {}

    var dropShadow:DropShadowFilter = new DropShadowFilter();

    dropShadow.distance = 4;

    dropShadow.angle = 90;

    dropShadow.color = 000.

    dropShadow.alpha =.5

    dropShadow.blurX = 10;

    dropShadow.blurY = 8;

    logo.filters = new Array (dropShadow);

    }

    mybtn.x = 515;

    mybtn.y = 259;

    mybtn.Alpha =. 8;

    staticpic.x = 480;

    staticpic.y = 270;

    staticpic.Alpha =. 4;

    logo.x = 37;

    logo.y = 11;

    myVideo.addEventListener (VideoEvent.COMPLETE, completePlay);

    mybtn.addEventListener (MouseEvent.MOUSE_UP, proofreading);

    function completePlay(e:VideoEvent):void {}

    addChild (mybtn);

    addChildAt(staticpic,0);

    removeChild (myVideo);

    }

    function replay(e:MouseEvent):void {}

    addChildAt(myVideo,0);

    myVideo.play ();

    removeChild (mybtn);

    removeChild (staticpic)

    }

    addChildAt(myVideo,0);

    addChildAt (logo, 1);

    init();

  • removeChild to clip that was added in another function?

    Hello everyone.  I have 3 different functions for my preloader.  I have an Event.OPEN and a ProgressEvent.PROGRESS Event.COMPLETE.  In the event. Opening function, I create a new variable that is typed the name of class of my preloader I put in its data property dialog box.  It's just an animation simple circle.  Here is my code for this:

    function addPreloader(event:Event):void
    {
    var myPreloader:mcPreloader = new mcPreloader();
    myPreloader.x = stage.stageWidth / 2;
    myPreloader.y = stage.stageHeight / 2;
    myPreloader.width = 75;
    myPreloader.height = 75;
    addChild (myPreloader);
    }

    My looks of function ProgressEvent.PROGRESS as follows:

    function preloadImages(event:ProgressEvent):void
    {
    var p: Number = Math.round (event.bytesLoaded/event.bytesTotal * 100);
    percent_txt. Text = % + '% ';
    }

    and my Event.COMPLETE function looks as follows:

    function imageLoaded(event:Event):void
    {
    var myLoadedImage:Loader = Loader (event.target.loader);
    addChild (myLoadedImage);

    new Tween (Strong.easeIn, 0, 1, 0.5, myLoadedImage, "alpha", true);

    event.target.loader.removeEventListener (Event.OPEN, addPreloader);
    event.target.loader.removeEventListener (ProgressEvent.PROGRESS, preloadImages);
    event.target.loader.removeEventListener (Event.COMPLETE, imageLoaded);
    }

    The only problem is that when it's done loading, I would remove the myPreloader from the scene.  Because it is declared in the function Event.OPEN, I can not connect with him via my Event.COMPLETE function.  How can I successfully remove from the scene once he's done loading?  Thank you!


    Jesse

    Declare it outside your function.  you don't need to create or add to the scene until the auditing function is called.

  • call a function to listener programmatically

    I have a function that is called on a ListEvent. I want to call it programmatically on the startup of the program as the default even if the user has not triggered the event.

    How can I do this?

    var tmpE:ListEvent = new ListEvent;
    tmpE.index = 0;
    
    onItemSelected(tmpE);
    
    private function onItemSelected(e:ListEvent):void {
          // some code
    }
    

    It is called and it works very well when the event is raised, but I would like the event to be triggered or call the listener automatically function at startup.

    Dave

    Thanks for the responses... Sorry to be a clear, I was really tired when the post was created.

    I want to be clicked on the list box (blue list as a user has clicked on it by default)

    I call the function of default listener like this:

    var tmpE:ListEvent = new ListEvent("listItemClicked", null, 0, 0, 0, 0, null);
    onItemSelected(tmpE);
    

    and he calls this function to listener:

    private function onItemSelected(e:ListEvent):void {
        if (currentList) {
            rightContainer.removeChild(currentList);
            currentList = null;
        }
    
        trace ("cell:" + e.cell + " data:" + e.data);
    
        switch (e.index) {
            case 0:
                trace("About");
                buildAbout();
                break;
            case 1:
                trace("General");
                break;
        }
        if (currentList) {
            rightContainer.addChild(currentList);
            rightContainer.layout();
        }
    }
    

    The listener function works perfectly if the user selects a list item, it relies also the default option at the start of the first section of code without problem, but the words or the first item in the list is not selected.

    When the program loads the first item by default, it is not obvious to the user that the first item in the list is already loaded and selected because the list item is not selected...

    Thanks for your help guys.

    @pyth... use it in future thanks.

  • Need help with removeChild

    I so want to do this stuff of animation, which, once the function buttonOff() is called, the existing button is removed, and after 3 seconds it will return. But I can't seem to put the button on

    private function buttonOff():void
            {
                Button3=new LabelButton();
                Button4=new LabelButton();
                Button3.label="Hello";
                Button4.label="There";
                Button4.x=200;
    
                this.removeChild(Button3);
                this.removeChild(Button4);
    
                setTimeout(addBtnChild,3000);
    
            }
    
            private function addBtnChild():void
            {   
    
                this.addChild(Button3);
                this.addChild(Button4);
            }
    

    Hey torres.

    you get compile errors? I don't see where you add the children initially. usually, when you delete an object that is not a child of the parent calling the removeChild method, it throws an error saying that it must be a child. What exactly is what your buttonOff function looks like?

  • addChild; removeChild; addChild

    I have two questions. The first is a specific question (bonehead). The second is more general in nature.

    I try to add a paragraph ("box" MC) text to the movieclip master, it melted and fondu melted apart, remove dynamically, to add the following paragraph and repeat. Here is my as:

    Add box of
    var box_inst:box = new box();
    addChild (box_inst)

    fade in box
    var myTweenX:Tween = new Tween (Strong.easeOut, 0, 1, 6, box_inst, "alpha", true);
    myTweenX.addEventListener (TweenEvent.MOTION_FINISH, doNextTween);

    fade in out of box
    function doNextTween(e:TweenEvent):void {}
    var myTweenAlpha:Tween = new Tween (box_inst, "alpha", Strong.easeIn, 0, 1, 2, true);

    Look for box finish
    myTweenAlpha.addEventListener (TweenEvent.MOTION_FINISH, removeBox);
    }

    Delete "box" and add "box2".
    function removeBox (evt:Event): void
    {
    removeChild (box_inst);
    var box_inst2:box = new box();
    addChild (box_inst2);
    }

    My first question is: "why not load"box_inst2 '?"

    And my second question... Finally I'll run this same process on a few dozen paragraphs. How this is accomplished more effectively? A table? Charger? Not looking for specific script - I will never learn it it - just a direction.

    Thanks, Dan

    It would be = garbage collector.

    class tween Adobe does not support a property of late.  among other shortcomings, that is why many of us use the 3rd party tween classes.  I love greensock (for example, tweenmax and tweenlite) classes.

    You can find a solution by using the adobe tween class and the class timer, but it is so much easier using the greensocks classes.  for example:

    Adobe tween class:

    Import fl.transitions.Tween;

    var delay_int:int = 5000;

    var t:Timer = new Timer(delay_int,1);

    t.addEventListener (TimerEvent.TIMER, delayF);

    Add box of
    var box_inst:box = new box();
    addChild (box_inst)

    var myTweenAlpha:Tween

    fade in box
    var myTweenX:Tween = new Tween (box_inst, "alpha", Strong.easeOut, 0, 1, 1, true);
    myTweenX.addEventListener (TweenEvent.MOTION_FINISH, doNextTween);

    fade in out of box
    function doNextTween(e:TweenEvent):void {}
    t.Start ();
    }

    function delayF(e:TimerEvent):void {}

    myTweenAlpha = new Tween (box_inst, "alpha", Strong.easeIn, 0, 1, 2, true);

    Look for box finish

    myTweenAlpha.addEventListener (TweenEvent.MOTION_FINISH, removeBox);

    }

    Delete "box" and add "box2".
    function removeBox (evt:Event): void
    {
    removeChild (box_inst);
    var box_inst2:box = new box();
    addChild (box_inst2);
    }

    greensocks tween class


    import com.greensocks.TweenLite;

    var delay_int:int = 5;

    var box_inst:box = new box();

    addChild (box_inst)

    fade in box

    TweenLite.from(box_inst,1,{alpha:0,onComplete:doNextTween,delay:delay_int});)

    function doNextTween (): void {}

    TweenLite.to(box_inst,1,{alpha:0,onComplete:removeBox});)

    }

    function removeBox (): void {}

    var box_inst2:box = new box();

    addChild (box_inst2);

    removeChild (box_inst);

    TweenLite.to

    }

    (p.s when you use the adobe forums, check useful/correct, if there is.)

Maybe you are looking for