Stage.addchild

Hi,
This is my Document Class
package BowerPower.Startup{
import flash.display.MovieClip;
import flash.events.Event;
public class Preloader extends MovieClip {
  public function Preloader() {
   stage.addChild(Preloader);
I have a movieclip in the library exported for actionscript. With a Class: Preloader.  The Bace Class: flash.display.MovieClip.
My problem is I get the error: 1067: Implicit coercion of a value of type Class to an unrelated type flash.display:DisplayObject.
How do I fix this,
Thanks

A couple of problems:
1. You're trying to add a class to the stage instead of an instance of the child
2. Generally, the movieclip shouldn't add itself to the stage (displaylist).  You should do it from outside.
So something like this (from outside your Preloader class (perhaps a Main class):
// Import the class
import BowerPower.Startup.Preloader;
// Create the instance and add it to the displaylist
var p:Preloader = new Preloader();
addChild(p);

Similar Messages

  • Stage.addChild in static function?

    In my document class (called "Level") I have a function:
    public function doSomething():void {
         stage.addChild(some_mc);
    In another class I'm trying to call this function with:
    Level.doSomething();
    but I get this error:
    1061: Call to a possibly undefined method doSomething through a reference with static type Class.
    if I make the function static I get this error:
    1120: Access of undefined property stage.
    I'm not sure what to do here. Some help would be appreciated. Thanks.

    Hello,
    @tlhood
    This is how you could do that:
    package
         import flash.display.MovieClip;
         public class Level extends MovieClip
              public static function doSomething():void
                   instance.stage.addChild(instance.some_mc);
              public function Level()
                   Level.instance = this;
              // instance is class variable
              private static var instance:Level = null;
              // stage/some_mc are instance variables
              private var some_mc:MovieClip = null;
    Level.doSometing();
    but most probably you would rather use singleton like implementation instead of static access in case you've e.g. single Level object in game:
    http://www.squidoo.com/flash-tutorials_as3-singleton-design-pattern
    so you would call:
    Level.getInstance().doSomething();
    or:
    // somewhere in code
    var level:Level = Level.getInstance();
    // sometimes later in some other part of code
    level.doSomething();
    regards,
    Peter

  • Is it possible to load a URL on stage?

    Hi,
    I'm using Flash CC-Action Script 3, is it possible to load a URL onto the stage?

    Thanks. I think our IT department will handle it since they do html/java/and
    all that stuff except for action script/flash. I am a little desperate
    though. I need to have this at least display a working clock for know and
    the phone list, which will display fine once I get to it. Can you be so kind
    and look at my horrible action script and help me get the clock to work
    continuously and show minutes under 10 with a "0"?  I just need to have
    something to show for our Annual Management meeting.
    Thank you sincerely for your time.
    Code:
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.Font;
    import flash.text.TextFormat;
    import flash.display.Sprite;
    import flash.text.*;
    import flash.filters.BitmapFilter;
    import flash.filters.BitmapFilterQuality;
    import flash.filters.BlurFilter;
    import flash.display.Bitmap;
    import flash.display.Loader;
    import flash.net.URLRequest;
    var link:URLRequest = new URLRequest("http://simplegreen.com/");
    //ADD CONTAINERS
    var containerStage:Sprite = new Sprite();
    containerStage.tabChildren = false;
    stage.addChild (containerStage);
    //DATE TIMER
    var my_date:Date = new Date();
    var my_timer:Timer = new Timer(1000);//create a new timer that ticks every
    second
    my_timer.addEventListener(TimerEvent.TIMER, onTimer);
    my_timer.start();
    //MONTH AND DATE
    var months:Array = ["Jan", "Feb", "Mar", "Apr", "May", "June", "Jul", "Aug",
    "Sept", "Oct", "Nov", "Dec"];
    var days:Array = ["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri"];
    var todayIs = (days[my_date.day] + "," + " " + months[my_date.month]  +" " +
    my_date.date + " " + my_date.fullYear);
    trace(days[my_date.day] + "," + " " + months[my_date.month]  +" " +
    my_date.date + " " + my_date.fullYear);
    //Text Loader
    var textLoader:URLLoader = new URLLoader();
    textLoader.addEventListener(Event.COMPLETE, textLoaded);
    textLoader.load(new URLRequest("assets/phoneList.txt"));
    var ampm:String = new String();
    var zero:String = new String();
    if (my_date.hours<12) {ampm = "AM";
    else{
    ampm = "PM";
    while(my_date.hours > 12){my_date.hours = my_date.hours - 12;
    if(my_date.minutes < 10){zero = "0" + my_date.minutes;
    else{
    my_date.minutes;
    function onTimer(e:TimerEvent):void {
    //my_date = new Date();
    trace(my_date.hours + ":" + my_date.minutes);
    var myDateTextBox:TextField = new TextField;
    myDateTextBox = new TextField();
    // myDateTextBox = todayIs;
    var dateStyle:TextFormat = new TextFormat;
    dateStyle.color = 0xFFFFFF;
    dateStyle.size = 48;
    dateStyle.font = "myriadMm";
    dateStyle.align = "left";
    var myTimeTextBox:TextField = new TextField;
    myTimeTextBox = new TextField();
    myDateTextBox.text = String(days[my_date.day] + "," + " " +
    months[my_date.month]  +" " +  my_date.date + " " + my_date.fullYear);
    myDateTextBox.width = 600;
    myDateTextBox.x = 70;
    myDateTextBox.y = 70;
    myDateTextBox.setTextFormat(dateStyle);
    //Add it to the stage;
    containerStage.addChild(myDateTextBox);
    myTimeTextBox.text = String(my_date.hours + ":" + my_date.minutes + " " +
    ampm);
    myTimeTextBox.width = 600;
    myTimeTextBox.x = 70;
    myTimeTextBox.y = 117;
    myTimeTextBox.setTextFormat(dateStyle);
    //Add it to the stage;
    containerStage.addChild(myTimeTextBox);
    //Event Listeners
    phone.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame);
    function fl_ClickToGoToAndPlayFromFrame(event:MouseEvent):void
    trace("directory ready");
    simpleGreen.addEventListener(MouseEvent.CLICK,
    fl_ClickToGoToAndPlayFromFrame_2);
    function fl_ClickToGoToAndPlayFromFrame_2(event:MouseEvent):void
    navigateToURL(link, "_self");
    videoDirectory.addEventListener(MouseEvent.CLICK,
    fl_ClickToGoToAndPlayFromFrame_3);
    function fl_ClickToGoToAndPlayFromFrame_3(event:MouseEvent):void
    trace("Video Player is Ready");
    function textLoaded(evt:Event):void
    info_txt.htmlText = textLoader.data;
    With warmest regards,
    Mary Crotteau
    Graphic Design Specialist
    Sunshine Makers, Inc./Simple Green

  • Objects added to the stage are not animated by AnimatorFactory

    Hi all,
    the following code ist a very simple animation. I added an object to the stage by dragging it from the library. Then I applied code generated by "Copy motion as AS 3" and the animation works fine.
    However, if i add another object by instating it in AS, add it to the stage by stage.addChild(...), and try to animate it by adding it as a target to the AnimatorFactory nothing happens.(Probably I made a simple newbi mistake.)
    Any ideas how to fix this? Thanks a lot in advance.
    Here is the code:
    import fl.motion.AnimatorFactory;
    import fl.motion.MotionBase;
    import flash.filters.*;
    import flash.geom.Point;
    var __motion_Symbol1_3:MotionBase;
    if(__motion_Symbol1_3 == null) {
        import fl.motion.Motion;
        __motion_Symbol1_3 = new Motion();
        __motion_Symbol1_3.duration = 34;
        // Call overrideTargetTransform to prevent the scale, skew,
        // or rotation values from being made relative to the target
        // object's original transform.
        // __motion_Symbol1_3.overrideTargetTransform();
        // The following calls to addPropertyArray assign data values
        // for each tweened property. There is one value in the Array
        // for every frame in the tween, or fewer if the last value
        // remains the same for the rest of the frames.
        __motion_Symbol1_3.addPropertyArray("x", [0,10.6348,21.2697,31.9045,42.5394,53.1742,63.809,74.4439,85.0787,95.7136,106.348,116.983 ,127.618,138.253,148.888,159.523,170.158,180.792,191.427,202.062,212.697,223.332,233.967,2 44.601,255.236,265.871,276.506,287.141,297.776,308.411,319.045,329.68,340.315,350.95]);
        __motion_Symbol1_3.addPropertyArray("y", [0,-0.151515,-0.30303,-0.454545,-0.60606,-0.757575,-0.90909,-1.06061,-1.21212,-1.36364,-1 .51515,-1.66667,-1.81818,-1.9697,-2.12121,-2.27273,-2.42424,-2.57576,-2.72727,-2.87879,-3. 0303,-3.18182,-3.33333,-3.48485,-3.63636,-3.78788,-3.93939,-4.09091,-4.24242,-4.39394,-4.5 4545,-4.69697,-4.84848,-5]);
        __motion_Symbol1_3.addPropertyArray("scaleX", [1.000000]);
        __motion_Symbol1_3.addPropertyArray("scaleY", [1.000000]);
        __motion_Symbol1_3.addPropertyArray("skewX", [0]);
        __motion_Symbol1_3.addPropertyArray("skewY", [0]);
        __motion_Symbol1_3.addPropertyArray("rotationConcat", [0]);
        __motion_Symbol1_3.addPropertyArray("blendMode", ["normal"]);
        // Create an AnimatorFactory instance, which will manage
        // targets for its corresponding Motion.
        var __animFactory_Symbol1_3:AnimatorFactory = new AnimatorFactory(__motion_Symbol1_3);
        __animFactory_Symbol1_3.transformationPoint = new Point(0.500000, 0.500000);
        // Call the addTarget function on the AnimatorFactory
        // instance to target a DisplayObject with this Motion.
        // The second parameter is the number of times the animation
        // will play - the default value of 0 means it will loop.
        __animFactory_Symbol1_3.addTarget(myClip, 0);
    var myClip1:Symbol1 = new Symbol1();
    stage.addChild(myClip1);
    __animFactory_Symbol1_3.addTarget(myClip1, 0); // NOTHING HAPPENS?

    if you create an animation that you want to apply to mulitple objects in cs4, you can create a motion preset:
    http://www.gotoandlearn.com/play?id=88
    in your coding problem, instead of adding myClip1 to the stage, add it to the main timeline.

  • Can i assign a child state to a movie clip that is already placed on stage

    Hello
    Is it possible to add a child state to a movie clip that is
    already placed on stage,
    i need to do this so i can move the movieclip to the top of
    the display list.
    thanks for the help
    mt

    "The objects i want it to appear above are loaded swf's onto
    the same main stage."
    Aha, this is where things can get confusing. The terminology
    between the Flash Authoring tool and ActionScript is not
    consistent.
    In ActionScript, the Stage is the top most DisplayObject. You
    probably get that.
    In Flash, the canvas that is often referred to as "the stage"
    is not the Stage object of ActionScript, rather the Flash stage is
    a DisplayObject class called MainTimeline (or if you assign a
    document class, it's that class), which is the first and only child
    of the ActionScript Stage object. It's the only child unless, of
    course, you add something else to the ActionScript Stage object at
    runtime... like a loaded swf. ;)
    So in other words, if you are doing anything like this:
    stage.addChild(myLoadedSWF)
    You are actually putting myLoadedSWF above the MainTimeline
    object, which is the entire Flash timeline. There's nothing wrong
    with that, but in this case it means changing the depth of things
    inside the MainTimeline is not going to change the fact that the
    MainTimeline itself is below myLoadedSWF.
    Most likely the simplest solution is to add your loaded SWFs
    to the property "root", not stage. root can refer to different
    things in different places, but most of the time it refers to the
    MainTimeline, and if I had to guess I would say it almost certainly
    does in your case. Note that the "root" property is typed as a
    DisplayObject, not a DisplayObjectContainer, so addChild (which is
    a DisplayObjectContainer method) will not be recognized unless you
    typecast to DisplayObjectContainer or a subclass of
    DisplayObjectContainer, like Sprite or MovieClip:
    MovieClip(root).addChild(myLoadedSWF)
    Also note that, unlike AS2, in AS3 it's very easy to simply
    add your loaded SWF below existing objects you create in Flash. You
    can use addChildAt(obj,0) for instance to add it to the very
    bottom.

  • Simple question: addChild

    Hi all!
    I got a simple question. I have one SWF with a document class with code in there. My stage
    is empty except one background image for the application. In the document class I added all
    stuff I need to stage (addChild(new MyClass())). When I test it with CTRL+ENTER (Air Debug
    Launcher - mobile) everything is working fine. When I add it to iTunes and then to my iPhone 4,
    nothing except the background image is shown up.
    When I add the the content directly to the stage in flash, everything is working right. Why addChild
    is not adding stuff to my stage?
    Please help, thanks
    Robert

    Hi, send me a link to your scene and I will try to help you if you want

  • Not centering on stage, why?

    Hello again folks. I've come across a new snag to a previous project. I'm not quite sure why, but when the full image is loaded to the stage, it is not centering it properly. The trace of fullLoader returns "0" for the width and height of the full-sized image, and I'm not quite sure how to pass the necessary information into the showPicture function so that it correctly centers the image. I tried tracing the content of fullLoader and got an error message. Any help would be appreciated.
    import flash.display.*;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import flash.filters.*;
    var fadeTween:Tween;
    var imageLoader:Loader;
    var fullLoader:Loader = new Loader;
    var xml:XML;
    //parse XML data as an array
    var xmlList:XMLList;
    var xmlLoader:URLLoader = new URLLoader();
    var thumbDShadow:DropShadowFilter = new DropShadowFilter();
    thumbDShadow.color = 0x000000;
    thumbDShadow.blurX = 10;
    thumbDShadow.blurY = 10;
    thumbDShadow.distance = 3;
    xmlLoader.load(new URLRequest("data/gallery.xml"));
    xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
    function xmlLoaded(event:Event):void {
        xml = XML(event.target.data);
        //parse the nodes in the XML file
        xmlList = xml.children();
        //count the number of nodes in the XML file via XMLList
        trace(xmlList.length());
        //loop to load all of the thumbnails, based on the number of nodes in XMLList
        for (var i:int = 0; i < xmlList.length(); i++) {
            imageLoader = new Loader();
            imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
            //position of thumbs (horizontally across stage)
            imageLoader.x = i * 110 + 10;//thumbs are 100 x 100 so, +10 to the width, plus +10 from left edge
            imageLoader.y = 10;
            imageLoader.name = xmlList[i].attribute("source");
            imageLoader.filters = [thumbDShadow];
            //add thumbnails to stage
            addChild(imageLoader);
            //set up thumbs to load primary image
            imageLoader.addEventListener(MouseEvent.CLICK, showPicture);
    function showPicture(event:MouseEvent):void {
        fullLoader.unload();
        fullLoader.load(new URLRequest(event.target.name));
        //position full image below the row of thumbs and center to stage
        fullLoader.x = (stage.stageWidth - fullLoader.width) * 0.5;
        fullLoader.y = (stage.stageHeight - fullLoader.height) * 0.5;
        addChild(fullLoader);
        fadeTween = new Tween(fullLoader, "alpha", None.easeNone, 0, 1, 0.5, true);
        trace("Stage: " + stage.stageWidth + " wide by " + stage.stageHeight + " tall.");
        trace("FullLoader is: " + fullLoader.width + " wide by " + fullLoader.height + " tall.");

    OH! Wow, okay now this makes much more sense now. The amended showPicture function is now:
    function showPicture(event:MouseEvent):void {
        fullLoader.unload();
        fullLoader.load(new URLRequest(event.target.name));
        fullLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, addToStage);
        function addToStage(event:Event):void {
            //position full image below the row of thumbs and center to stage
            fullLoader.x = (stage.stageWidth - fullLoader.width) * 0.5;
            fullLoader.y = (stage.stageHeight - fullLoader.height) * 0.5 + 110;
            addChild(fullLoader);
            fadeTween = new Tween(fullLoader, "alpha", None.easeNone, 0, 1, 0.5, true);
            trace("Stage: " + stage.stageWidth + " wide by " + stage.stageHeight + " tall.");
            trace("FullLoader is: " + fullLoader.width + " wide by " + fullLoader.height + " tall.");
    AWESOME! Thanks so much for your help!

  • Adding a shape to Stage using AS3

    I'm trying to add a rectangle to the stage.
    I've imported the following...
    ActionScript Code:
    import flash.display.Shape;
    I then instantiate my shape variable in my Document Class...
    ActionScript Code:
    public var floatArea:Shape = new Shape();
    And finally I set the position, size and colour of my rectangle then add it to the stage in my Class Constructor...
    ActionScript Code:
    floatArea.graphics.drawRect(40, 400, 1120, 170);
    floatArea.graphics.beginFill(0x000000);
    stage.addChild(floatArea);
    So why isn't the rectangle showing up on my stage?

    Sorted it now!
    The tutorial I was looking at said that in some cases you don't need to add .graphics.endFill();
    However, in my case I did! I also had to put the .graphics.beginFill(0x000000); first, then the drawRect command.  Not sure why this is, must be some syntax rule Actionscript has...it's a Sunday so can't be bothered thinking about it too hard!
    Anyway, here's the code I used to get it working...
    ActionScript Code:
    floatArea.graphics.beginFill(0x000000);
    floatArea.graphics.drawRect(40, 400, 1120, 170);
    floatArea.graphics.endFill();
    stage.addChild(floatArea);

  • Loading JPEGs into set position on stage

    Hi All,
    I have made a flash movie as seen at
    http://www.coffeemamma.com.au
    and would
    like to change the following:
    I'd like to generate three random numbers from 1 to 5
    inclusive but I want
    to ensure that each number is different - e.g. 2, 4, 1 (not
    2, 4, 2). I know
    how to generate ONE random number, but I'm stuck on comparing
    them to see
    whether they are the same (and if they are, then generate new
    numbers until
    they are unique).
    With the three numbers I would like to load images based on
    those numbers -
    e.g. '_image_2.jpg' then '_image_4.jpg' then '_image_1.jpg'.
    This part is
    fine IF I can generate the numbers.
    I'd also like to have the images come to the front when they
    are hovered
    over with the mouse and then to go 'back' to their original
    position when
    the mouse moves away. This I'm completely stuck on.
    I'd also like to be able to put the newly loaded images into
    certain
    positions (as per the example) rather than only loaded to
    (0,0) coordinates.
    I also want to be able to have the images masked as they come
    in (as per the
    example) in order to avoid white corners on the top images.
    I also have a page as per
    http://www.wasabi.org.au/wodonga.shtml
    which has
    some of the functions I want to use, but I can't seem to get
    some of the
    functions working in my new movie...
    Many thanks,
    Bruce

    var arr:Array = new Array();
    var nextX:Number=whatever;  // assign these 4 numbers
    var nextY:Number =whateverelse;
    var gapX:uint = xx;
    var gapY:uint =yy;
    for(var i:int = 0; i<4; i++){
        var life_mc:Life = new Life();
        arr.push(life_mc);
        stage.addChild(life_mc);
       life_mc.x = nextX;
      life_mc.y=nextY;
    nextX += gapX*(i%2);
    nextY += gapY*Math.floor(i/2);

  • Can't get stage from a constructor method. Why?

    Hi,
    I'm making a kind of image showcase, what has a fluid width and height, depending on browser window dimensions. Everything is okay, I have other kind of issue: in constructor function in this gallery class I can't use stage property, I have to get it from main class.
    Why Flash treats me this way and how I can avoid this currentStage variable?
    Main code:
    package dev {
         import flash.display.Sprite;
         import flash.display.StageScaleMode;
         import flash.display.StageAlign;
         import flash.display.MovieClip;
         import flash.events.Event;
         import UI.BackgroundImageRotator;
         public class Application extends Sprite {
              public function Application():void {
                   stage.scaleMode = StageScaleMode.NO_SCALE;
                   stage.align = StageAlign.TOP_LEFT;
                   trace("Start.");
                   var BIR = new BackgroundImageRotator(stage);
                   stage.addChild(BIR);
    BackgroundImageRotator class:
    package UI {
         import flash.display.MovieClip;
         import flash.events.Event;
         import flash.display.Stage;
         public class BackgroundImageRotator extends MovieClip {
              protected var currentStage:Stage;
              public function BackgroundImageRotator(currentStage:Stage):void {
                   this.x = 0;
                   this.y = 0;
                   this.currentStage = currentStage;
                   currentStage.addEventListener(Event.RESIZE, onStageResize);
              protected function onStageResize(evt:Event):void {
                   trace(stage.stageWidth + ' ' + stage.stageHeight);

    if you have a display object that will be added to the display list, you need to wait until it is added before you can reference its stage property.  ie, use the Event.ADDED_TO_STAGE event.
    otherwise, you must pass a stage reference to your class.

  • How to clear the stage when entering a new frame

    Dear all,
    I am making my first website in flash based on frames. When you go to an other frame the Stage fades out. When you enter the frame you see nothing at all. So how can I clear the stage when entering the frame or even better it fades into the frame with clearing the objects & code of the previous frame.
    Hope somebody can help me with this!
    /*buttons naar frames*/ homehome.mouseChildren = false; homehome.buttonMode = true; homehome.addEventListener(MouseEvent.CLICK, actie5); homehome.addEventListener(MouseEvent.ROLL_OVER, actie5); homehome.addEventListener(MouseEvent.ROLL_OUT, actie5); var fadetimer:Timer; var st:MovieClip = new MovieClip(); function actie5(event:MouseEvent):void {   //klikken if(event.type == "click"){ st.graphics.beginFill(0xFFFFFF); //Choose your color to fade.         st.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);         st.graphics.endFill();         st.alpha = 0;         stage.addChild(st);         fadetimer = new Timer(100);         fadetimer.addEventListener(TimerEvent.TIMER, fadeStage);         fadetimer.start(); }   //roll over   if(event.type == "rollOver"){     infohome.text = "je staat op de knop";   }   //roll off   if(event.type == "rollOut"){     infohome.text = "";   } } function fadeStage(te:TimerEvent):void {     if (st.alpha < 1) {         st.alpha += 0.05;     } else {         fadetimer.stop();         fadetimer.removeEventListener(TimerEvent.TIMER, fadeStage);         gotoAndStop(7);     } }
    Thanks a lot for your time

    sorry can't get the code working properly onwith the html code function. Sorry for that

  • How to set timer intervals for object + and a motion for entering stage

    Hi, I am making a simple game but I have a couple problems/queries.
    1) My game is a touch an object and you get a point game, currently the objects appear randomly over the screen, however I am trying to get it to slide into the screen similar to the Fruit Ninja game, but not limited to entering from one side, does anyone know how to set this?
    2) As I mentioned above my objects appear randomly, I have set a timer when I change the timer from 800 to another number, it just makes all the objects on the screen last for 800 milliseconds all at the same time then disappear and appear somewhere else on the screen for another 800 milliseconds and it repeats, what I am trying to do is make them come at different intervals, for example:
    Object 1 - constantly appears, so when the 800 millisecond is over, it comes back on a different part of the stage
    Object 2 - I want it to appear every 5 seconds, so when the 800 millisecond is over it will come back on the stage in 5 seconds, but not instantly like Object 1
    But I have no idea how to do this :/ anyone have the code needed for me to do this?
    Sorry for the long questions, I only asked because I really am stuck, I have been trying to do this for over 2 weeks now.
    Thanks very much.
    My Code
    [Code]
    //importing tween classes
    import fl.transitions.easing.*;
    import fl.transitions.Tween;
    import flash.utils.Timer;
    //hiding the cursor
    Mouse.hide();
    var count:Number = 60;
    var myTimer:Timer = new Timer(1000,count);
    myTimer.addEventListener(TimerEvent.TIMER, countdown);
    myTimer.start();
    function countdown(event:TimerEvent):void {
    myText_txt.text = String((count)-myTimer.currentCount);
    if(myText_txt.text == "0"){
    gotoAndStop(5)
    //creating a new Star instance;
    var star:Star = new Star();
    var box:Box = new Box();
    var bomb:Bomb = new Bomb();
    //creating the timer
    var timer:Timer = new Timer(800);
    var timerbox:Timer = new Timer(850);
    var timerbomb:Timer = new Timer(1000);
    //we create variables for random X and Y positions
    var randomX:Number;
    var randomY:Number;
    //variable for the alpha tween effect
    var tween:Tween;
    //we check if a star instance is already added to the stage
    var starAdded:Boolean = false;
    var boxAdded:Boolean = false;
    var bombAdded:Boolean = false;
    //we count the points
    var points:int = 0;
    //adding event handler to the timer;
    timer.addEventListener(TimerEvent.TIMER, timerHandler);
    //starting the timer;
    timer.start();
    function timerHandler(e:TimerEvent):void
              //first we need to remove the star from the stage if already added
              if (starAdded)
                        removeChild(star);
              if (boxAdded)
                        removeChild(box);
              if (bombAdded)
                        removeChild(bomb);
              //positioning the star on a random position
              randomX = Math.random() * 800;
              randomY = Math.random() * 1280;
              star.x = randomX;
              star.y = randomY;
              star.rotation = Math.random() * 360;
              box.x = Math.random() * stage.stageWidth;
              box.y = Math.random() * stage.stageHeight;
              box.rotation = Math.random() * 360;
              bomb.x = Math.random() * stage.stageWidth;
              bomb.y = Math.random() * stage.stageHeight;
              bomb.rotation = Math.random() * 360;
              //adding the star to the stage
              addChild(star);
              addChild(box);
              addChild(bomb);
              //changing our boolean value to true
              starAdded = true;
              boxAdded = true;
              bombAdded = true;
              //adding a mouse click handler to the star
              star.addEventListener(MouseEvent.CLICK, clickHandler);
              box.addEventListener(MouseEvent.CLICK, clickHandlerr);
              bomb.addEventListener(MouseEvent.CLICK, clickHandlerrr);
    function clickHandlerr(e:Event):void
              //when we click/shoot a star we increment the points
              points +=  5;
              //showing the result in the text field
              points_txt.text = points.toString();
                        if (boxAdded)
                        removeChild(box);
              boxAdded = false;
    function clickHandler(e:Event):void
              //when we click/shoot a star we increment the points
              points++;
              //showing the result in the text field
              points_txt.text = points.toString();
              if (starAdded)
                        removeChild(star);
              starAdded = false;
    function clickHandlerrr(e:Event):void
              gotoAndPlay(5);
    [/Code]

    The only thing that affects TopLink is the increment by, as increasing this is what allows TopLink to reduce the number of times it needs to go to the database to get additional numbers. Ie, an increment value of 1 means TopLink needs to go the database after each insert; an increment value of 50 allows it to insert 50 times before having to get a value from the sequence. The cache on the sequence object in the database affect the database access times. While it may improve the access times when the sequence number is obtained from the database, but I believe the network access to obtain the sequence is the greater concern and slow down for most applications. It all depends on the application usage and design though - an increment (and application cache) of 50 numbers seems to be the best default.
    I cannot say what effect the cache vs nocache settings will have on your application, as it will depend on the database load. Only performance testing and tuning will truly be able to tell you whats best for your application.
    Best Regards,
    Chris

  • AddChild in non-document class

    Hello, I'm trying to migrate the hundreds of lines of code in
    my main actions frame into classes.
    Could someone be so kind as to tell me how to use the
    addChild in a class that isn't the document class. I have got my
    file structure setup with the package folder and the main document
    class in the .fla root.
    I can trace from secondary classes but not use addChild and I
    am about to lose my mind!
    I have included one of my the classes so you can see how I
    have worked it.

    I am trying to catch up to AS3 from older versions of Flash,
    so I may be wrong about this.
    from what I understand, the only way to reference the stage
    is to use the stage property from an item already on the stage,
    such as your main document class (or another sprite or movie clip
    on the stage). as it stands you are adding 'aCloud' as a child of
    the new CloudClass object, not as a child of the stage. so..
    MyClouds.stage.addchild(aCloud);
    also, the other poster was right about the typo--
    aCloud:captionCloud = new captionCloud();
    one other thing I don't understand, maybe I'm missing
    something-- where is the "captionCloud" class? is it public, or at
    least accessable by CloudClass? also wouldn't it be a better idea
    to define all the properties for a captionCloud object in a method
    of the captionCloud class, and then use CloudClass to control the
    relationship between all the different captionCloud objects (but
    not their internal properties such as alpha, x, y, etc). this seems
    more OOP appropriate to me.
    anyway, i'd like to know what finally works for you, please
    post your solution when you figure it out. i'm just starting on my
    1st AS3 project.

  • Createjs adding mc to stage

    Hi I used to do quite a bit of as3 word but not for quite some time (guess why???).  I am now having a play with flash pro6 and the toolkit for create js. I have to say I worked through the platypus example and it kinda left out all the things I wanted to know like the real easy stuff! So for example I want to add a mc to the stage with js --- how? The as bit works ... but I tried various combinations of
    stop(); var fredd = new fred(); stage.addChild(fredd); fredd.x=100; fredd.y=100; /* js this.stop(); var fredd = new fred(); this.stage.addChild(fredd); */ 
    but I just kept getting an comment about empty symbols and a helpful reminder about the timeline starting at 1. I feel sure this is very easy,  but I can't figure it out! Perhaps there is a real beginners resource somewhere that I am missing? Thanks

    Here is a simple example of a fla that adds an mc to the stage with CreateJs:
    http://www.ronaldliauw.nl/assets20130219/examples/AddMc/
    And here is a complex CreateJs example:
    http://www.ronaldliauw.nl/assets20130219/examples/bouwplaat/
    In both examples the swf and the html generated with 'Toolkit for CreateJs' do  the same.
    In both examples the swf is faster.

  • Issue referencing stage

    I think my issue is to do with referencing the stage, but not to sure.  When I try
    var screen:Sprite = new Sprite();
    screen.graphics.beginFill(0x111111, .75);
    screen.graphics.drawRect(0,0, stage.stageWidth, stage.stageHeight);
    screen.graphics.endFill();
    I get the error
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    If I change stage.stageWidth, stage.stageHeight to numbers, it works fine.  So I think the problem is to do with referencing the stage.  Whats confusing me though is if I set the above to numbers, later on in my code I have
    TweenLite.to(loaderHolder, 1, { x: (stage.stageWidth - loaderHolder.width) / 4, y: (stage.stageHeight - loaderHolder.height) / 6, onComplete:zoomInFinished, scaleX: 1, scaleY: 1 });
    So I am referencing the stage there.  However, this works without a problem.
    If it makes a difference, I am working within a movieclip which is in my library, and added to the stage on the main timeline.  Within this movieclip, I do things like stage.addChild, so this works without a problem.  Why might the first bit of code be throwing a null reference error?
    cheers

    because you're trying to reference the stage before before your object is added to the display list.  to remedy, use the addedtostage event before trying to reference the stage.

Maybe you are looking for

  • Serial ports in Solaris 10

    Hi all. Please help me to solve my little problem. I need to get serial ports names (com-ports) registered in my system. In Linux I use command "dmesg | grep ttyS" for that, but in Solaris dmesg output don't contains any data about ttya, ttyb etc...

  • Structure mapping is incorrect....urgent

    Hi Folks, in the below code itab  and itab1 structures are diffetenr. I need to move itab1 data into itab from that itab i suppose to pass data to ztable. when i am chk below code i am getting error as structure is not mapping. Can u plz change the c

  • Dust under the LCD cover, sticky/non-responsive keyboard..

    Hello, I've been trying to find information on this. I purchased this phone, outright, from Bell when they finally started selling it a couple of weeks ago.  Since then, the phone has aquired a large amount of dust under the LCD cover (and continues

  • How to redownload a free version of whatsApp messenger.

    Please help me redownload a free version of whatsApp messenger because I deleted it and I can't download it again. It gives me the response that my request can not be completed at this time.

  • WL 6.0: How to make RDBMSRealm be the Realm

    Hi, I tried to use RDBMSRealm, but found out that it is FileRealm the system uses. I did not find a way to select which Realm to use by console. I manually modified config.xml, but no luck. Is there a way to use RDBMSRealm? Thanks.