Randomly generate movieClips from the library onto the stage

Hello

I'm calling the objects from the library for a collection set.

Major problems with how best to attribute the good and bad objects update later a score.

Can anyone help me how can I first assign the clips in the library in an array of good and bad and then after randomally fill the stage with them.

Concerning

James

see you never fake in your output panel, when using:

public void placeWords() {}

random location

var x: Number = Math.floor (Math.random () * mapRect.width) + mapRect.x;

var y: Number = Math.floor (Math.random () * mapRect.height) + mapRect.y;

check all blocks to see if it's over everything

var isOnBlock:Boolean = false;

for (var j: int = 0; j

If (blocks [j].hitTestPoint(x+gamesprite.x,y+gamesprite.y)) {}

isOnBlock = true;

break;

}

}

not on everything, so use location

trace (isOnBlock);

If (! isOnBlock)

{

var goodObjects:Array = ["WordObject1"];

var badObjects:Array = ["WordObject2"];

If (Math.Random)<>

{

var r: int = Math.floor (Math.random () * goodObjects.length);

var classRef: Class = getDefinitionByName (goodObjects [r]) in class;

var newObject:MovieClip = new classRef();

newObject.typestr = "good";

} else

{

r = Math.floor (Math.random () * badObjects.length);

classRef = getDefinitionByName(badObjects[r]) in class;

newObject = new classRef();

newObject.typestr = "bad";

}

gamesprite.addChild (newObject);

newObject.x = Math.floor (Math.random () * stage.stageWidth);

newObject.y = Math.floor (Math.random () * stage.stageHeight);

break;

}

}

Tags: Adobe Animate

Similar Questions

  • Remove a movieclip from the stage after a fixed amount of time (or once it has finished its animation)

    I have a movieclip animation that is added to the scene at the beginning of the .swf.  His introduction to the game and the user is asked to click on the movieclip to start the animation.

    Once the animation is complete, I would like the movieclip to be removed from the scene.

    How can I do this?  Can I set up a kind of event handler that listens on if the movieclip has completed then start a function once its finished out of the scene?  What methods to look out for the finishing of the movieclips?

    See you soon

    There is no particular event that is called when a movieclip stop playing games,

    what you could do is inside your shipment of movieclip intro an event as soon as the animation is completed

    something like... dispatchEvent (new Event ("introFinished");

    and all you have to do is add and event listener for movieclip intro intro.addEventListener ("introFinished", onIntroFinished);

    When your onIntroFinished is called, you can remove the intro to the scene.

  • Help to copy the timeline of the movieclip on the stage of chronology for exporting .mov

    Hello

    I'm under Flash CS5 on a Macbook Pro, version 10.6.8.

    I'm trying to convert .swf to a .mov to an animation I created. I already tried the 'export' in Flash Basic options, but it exports only the "scene 1" first frame and not the real movieclip (648 images) I created which is placed in the scene 1.» Of after online videos / websites, I've gathered that I need to copy the movieclip on the stage 1 layers and then export that normally. While I can do (select the layer of the timeline of the movieclip, make a right click Copy frames and then paste this layer in scene 1), glued on the stage of the layers are out of the original (movieclip). Is there a quick way to move all layers in the timeline (frames) the scene 1 without losing their location on the stage? It is a fair way to export the movieclip in. MOV directly without messing with the parent stage 1?

    Thanks in advance!

    If you stretched it scenario main enough to show all the images in 645 and there not animate, implying that there are more nesting inside that you need to take into account. You'll need transform these MC incorporated into graphics so and stretch out them to full length.

  • Dynamically loaded swf to communicate with the MovieClip on the stage

    I have a devil of a time here with a problem. I've got an xml document when it is clicked on a certain button on the stage, it loads its corresponding external swf into an empty movieclip on the stage. This empty clip is support for all external SWF.

    So what I'm trying to do, is when an external swf is loaded that has buttons on it, I need these buttons to communicate with the main timeline and delete an mc who is on the stage. I need the swf (s) currently loaded to be able to do. So whatever the currently loaded external swf is loaded, I need to talk to the main timeline. (I have external SWF files a certain need to do this) So I guess I have to somehow target the external swf currently loaded so he could talk to the main timeline.

    The code below in summary does not, but it gives no errors either. I don't pretend to know what I'm doing, and I did not find a solution to this particular problem. If someone could give me advice or direct me to a solution. I would be so happy.

    scenario focus

    var object: index = this;

    function loadComplete (e: Event) {}

    TweenMax.to (index.mcholder, 1, {alpha:. 5});

    Add the current module to the mcholder movieclip according to addChild

    index.mcholder.addChild (e.currentTarget.content);

    (e.currentTarget.content as MovieClip) .addEventListener ("eventTriggered", startListener);

    function startListener(e:Event):void {}

    var ext_swf:MovieClip;

    ext_swf = e.currentTarget.content as MovieClip;

    trace ("external swf");

    ext_swf. Button1.addEventListener (MouseEvent.CLICK, talktomainswf);

    function talktomainswf (): void {}

    TweenMax.to (index.mc_thatsonthestage, 1, {x: 1000});

    }

    }

    Now we have the first load we set to false firstLoad

    index.firstLoad = false;

    }

    function loadError (e: Event) {}

    trace ("Error");

    }

    }

    You can use the event to communicate with external SWF Dispatcher and a main timeline

    as follows:

    //in an external swf
    
    //Once loaded
    function onLoadComplete(event:Event):void
    {
         //dispatch an event in the form of a string
         dispatchEvent(new Event("Talk to Main Timeline"));
    }
    
    //On the Main timeline
    
    //listen for "Talk to Main Timeline"
    stage.addEventListener("Talk to Main Timeline", listenForCallsFromExternalFiles, true); 
    
    //if the event is heard, do this:
    function listenForCallsFromExternalFiles(e:Event):void
    {
         trace("I heard ya, now do stuff...");
    }
    

    That's the idea anyway, I use it all the time.

    hope that helps,

    ~ chipleh

  • Creating movieclips from the library "random" then move them.

    Hey everybody,

    I am currently working on a type of runner free 2D game for Android and iOS. What I'm trying to accomplish is spawning in some clips, which are sets of platforms formed how I'd like, when the game of previous platforms reaches a certain point on the left of the stage. I want the movieclip to come slightly to the right of the stage and move them to the left. This will keep spawning, randomly, one of the dozen sets platforms very much, making a runner for the infinite. The game I suppose that could be described as something like Jetpack Joyride, but platforms to add and subtract the jetpack. Anyone know it to spawn in movieclips and move them conditionally at best? Thank you in advance!

    -John

    To generate the library dynamically in aAS3 clips you must first assign a class name to each library.  Then add these class names in a table so that you can randomly select one of them.  To add them, you can use the name of the class as follows...

    var ClassRef: Class = Class (getDefinitionByName ("className"));

    var classInstance: * = new ClassRef();

    addChild (classInstance);

  • How to remove the object from the stage

    Hello

    I am currently implementing an AS3 code that generates a snow effect on the scene.  I am using the code from this site, but has difficulty:

    http://www.Kirupa.com/developer/flashcs4/falling_snow_as3_cs4_pg5.htm

    I have no difficulty in implementing of the snow, but I can't understand how get rid of it once it's there!  Here's the code, I have:

    (main.as)

    main/public class extends MovieClip

    {

    var snowamount = 50;

    public void main()

    {

    scene9. SnowPlus.addEventListener (MouseEvent.MOUSE_DOWN, moresnow);

    }

    function makeItSnow()

    {

    for (var i: int = 0; i < snowamount; i ++)

    {

    var newSnowFlake:Snowflake = new Snowflake();

    this.addChild (newSnowFlake);

    newSnowFlake.SetInitialProperties ();

    triggerSnowAnimation();

    }

    }

    function moresnow (MouseEvent): void

    {

    snowamount += 20;

    makeItSnow();

    }

    function triggerSnowAnimation()

    {

    If (snowamount > = 160)

    {

    scene9.gotoAndPlay (3);

    scene9. SnowPlus.Visible = false;

    }

    }

    (Snowflake.as)

    SerializableAttribute public class extends MovieClip Snowflake

    {

    private var xPos:Number = 0;

    private var yPos:Number = 0;

    private var xSpeed:Number = 0;

    private var ySpeed:Number = 0;

    private var radius: Number = 0;

    private var scale: Number = 0;

    private var alphaValue:Number = 0;

    private var maxHeight:Number = 0;

    private var maxWidth:Number = 0;

    public void Snowflake()

    {

    }

    public void SetInitialProperties()

    {

    xSpeed is.05 + Math.random () *.1;.

    ySpeed =.1 + Math.random () * 3;

    RADIUS =.1 + Math.random () * 2;

    Scale =.01 + Math.Random ();

    alphaValue =.1 + Math.Random ();

    var stageObject:Stage = this.stage in the stadium;

    maxWidth = stageObject.stageWidth;

    maxHeight = stageObject.stageHeight;

    This.x = Math.random () * maxWidth;

    This.y = Math.random () * maxHeight;

    PosX = this.x;

    yPos = this.y;

    this.scaleX = this.scaleY = scale;

    This.Alpha = alphaValue;

    this.addEventListener (Event.ENTER_FRAME, MoveSnowFlake);

    }

    function MoveSnowFlake(e:Event)

    {

    xPos += xSpeed;

    yPos += ySpeed;

    This.x += radius * Math.cos (xPos);

    This.y += ySpeed;

    If (this.y - this.height > maxHeight)

    {

    This.y = - 10 - this.height;

    This.x = Math.random () * maxWidth;

    }

    }

    }

    The code is not so difficult to understand, in fact.  I have a button that adds "snowamount" to the variable, so more snow is done on the scene when the button is clicked.  However, once the "snowamount" gets above 160 bee, I trigger an animation.  Once the animation is completed, I want the snow to disappear from the scene.  But I can't understand the correct way to do everything.  Any help would be appreciated!  Thank you very much in advance.

    create an array and store your references to Snowflake in this table.  When you are ready to remove the snow flakes, loop in the table.

    main/public class extends MovieClip

    {

    var snowamount = 50;

    var snowFlakeA:Array = [];

    public void main()

    {

    scene9. SnowPlus.addEventListener (MouseEvent.MOUSE_DOWN, moresnow);

    }

    function makeItSnow()

    {

    for (var i: int = 0; i< snowamount;="">

    {

    var newSnowFlake:Snowflake = new Snowflake();

    snowFlakeA.push (newSnowFlake);

    this.addChild (newSnowFlake);

    newSnowFlake.SetInitialProperties ();

    triggerSnowAnimation();

    }

    }

    function moresnow (MouseEvent): void

    {

    snowamount += 20;

    makeItSnow();

    }

    function triggerSnowAnimation()

    {

    If (snowamount > = 160)

    {

    scene9.gotoAndPlay (3);

    scene9. SnowPlus.Visible = false;

    }

    }

    (Snowflake.as)

    SerializableAttribute public class extends MovieClip Snowflake

    {

    private var xPos:Number = 0;

    private var yPos:Number = 0;

    private var xSpeed:Number = 0;

    private var ySpeed:Number = 0;

    private var radius: Number = 0;

    private var scale: Number = 0;

    private var alphaValue:Number = 0;

    private var maxHeight:Number = 0;

    private var maxWidth:Number = 0;

    public void Snowflake()

    {

    }

    public void SetInitialProperties()

    {

    xSpeed is.05 + Math.random () *.1;.

    ySpeed =.1 + Math.random () * 3;

    RADIUS =.1 + Math.random () * 2;

    Scale =.01 + Math.Random ();

    alphaValue =.1 + Math.Random ();

    var stageObject:Stage = this.stage in the stadium;

    maxWidth = stageObject.stageWidth;

    maxHeight = stageObject.stageHeight;

    This.x = Math.random () * maxWidth;

    This.y = Math.random () * maxHeight;

    PosX = this.x;

    yPos = this.y;

    this.scaleX = this.scaleY = scale;

    This.Alpha = alphaValue;

    this.addEventListener (Event.ENTER_FRAME, MoveSnowFlake);

    }

    function MoveSnowFlake(e:Event)

    {

    xPos += xSpeed;

    yPos += ySpeed;

    This.x += radius * Math.cos (xPos);

    This.y += ySpeed;

    If (this.y - this.height > maxHeight)

    {

    This.y = - 10 - this.height;

    This.x = Math.random () * maxWidth;

    }

    }

    function removeSnowF (): void {}

    for (var i: int = snowFlakeA.length - 1; i > = 0; i--) {}

    this.removeChild (snowFlakeA [i]);

    snowFlakeA.splice (i, 1);

    }

    }

    }

  • Set the movieclip to the stage

    Here is my code, I don't know why it is not f ' ing work?

    function newBomb() {}

    var newBomb = attachMovie ("bomb", "bomb");

    newBomb._x = 200;

    newBomb._y = 200;

    }

    newBomb();

    Please tell me what stupid thing I did.

    And Yes, the linkage/properties of the movieclip in the library are correct (link: bomb).

    Try to avoid using the same name for different things and see if it works.  Name of the instance, which is the same as the linkage and not to name the same as the function variable.

  • How to restrict the movement of movieclip on the stage?

    Hi, I want to spend my movieclip to the left and right, but he moves out of the scene. I want to restrict the movement of X the width of my step.

    This is my code for the movement of movieclip:

    import flash.events.KeyboardEvent;

    stage.addEventListener (KeyboardEvent.KEY_DOWN, moveavatar);

    function moveavatar (event: KeyboardEvent): void

    {

    If (event.keyCode is 39)

    {

    avatarmove.x += 10;

    }

    Else if (event.keyCode == 37)

    {

    avatarmove.x = 10;

    }

    }

    How do I limit the movement of X the width of my step so it won't leave the stage? Thank you.

    You have the registration point in the upper left corner. In my case, I had to focus. If you want to keep as you have, replace with this:

    import flash.events.KeyboardEvent;

    stage.addEventListener (KeyboardEvent.KEY_DOWN, moveavatar);

    function moveavatar(event: KeyboardEvent): void {}

    avatarmove.x = Math.max (0, Math.min (stage.stageWidth - avatarmove.width, avatarmove.x - int(event.keyCode==37) * 10 + int(event.keyCode==39) * 10))

    }

  • How to "call" a movieclip on the stage of in a movieclip?

    Hey,.

    I have therefore 2 video clips on the stage, and I have to call the 2nd movieclip of in that 1.

    Ive tried to use;

    "stage.popUp_mc.gotoAndStop (1);

    "root.popUp_mc.gotoAndStop (1);

    and it keeps bringing the errors

    Thanks :)

    Ollie.

    If you are using AS3 and the two movieclips live time on the root timeline, so you can try...

    MovieClip (root).popUp_mc.gotoAndStop (1);

    You could possibly use.

    MovieClip (parent).popUp_mc.gotoAndStop (1);

    A correct way more OO to do this would be to have an event listener in the main storyline that is assigned to the movieclip and listening to an event that distributes the movieclip.  The event in the main storyline listener would call a function in the main timeline that targets the second movieclip.

  • JavaScript generated pages from the model calculations

    I have a form that has 5 pages that allows adding pages from templates. None of the calculations or automatic tabs works. I am very new to javascript and have tried several forums without success. Here's what my age script looks like, how do I add so when that it generates the template it works correctly. Thanks in advance for the help.

    var util.scand = birth date ("mm/dd/yyyy", this.getField ("P3. (AttachmentA.VIC2DOB") .valueAsString);

    If (dob! = null) {}

    var today = new Date();

    var age = today.getFullYear () - dob.getFullYear ();

    var m = today.getMonth () - dob.getMonth ();

    If (m < 0 |) ((m = 0 & & today.getDate (), dob.getDate ())) {

    -years;

    }

    Event.Value = age;

    }

    else {}

    Event.Value = "";

    }

    Part of a working example, the calculation script on the page template for the age field:

    var cPreFix = "";
    get elements of prefix for pages having engineered;
    var aFieldName = event.target.name.split(".");
    If (aFieldName.Length > 2)
    {
    first 2 items makeup table name prefix for fields on a page having pioneered;
    cPreFix = aFieldName [0] + '. ' + aFieldName [1] + ".";
    }
    calculate age in years;
    var date of birth = util.scand ("mm/dd/yyyy", this.getField(cPreFix_+_"VIC2DOB").valueAsString);
    If (dob! = null) {}
    var today = new Date();
    var age = today.getFullYear () - dob.getFullYear ();
    var m = today.getMonth () - dob.getMonth ();
    If (m< 0="" ||="" (m="==" 0="" &&="" today.getdate()="">< dob.getdate()))="">
    -years;
    }
    Event.Value = age;
    }
    else {}
    Event.Value = "";
    }

    Your script does not remove the '0' value when there is no entry for the date of birth field.

  • XML schema to generate data from the table of data from a repeating subform

    Hi all, I would like to have a check box that when checked, allows you to hide a quote form and make a purchase order form visible, carrying a part of the field of the form of citation data in a new table on the order form. I have attached to this form to https://workspaces.acrobat.com/?d=pqpsXx5VPi * LkMeVKrX57w if you want to take a look. If the check box is cleared, he hid the PO form and to make quite visible.

    The idea behind this is that my client will create his quote and send t to his client. Once the customer accepts the quote, he simply click a button to generate its purchase order send it to its supplier.

    It seems that I have buttons to add lines on the submission form that the problem is more complex. I would be able to do it myself if the table has a fixed number of lines and I was able to use global fields, and naming each cell something different, but because it's a single repeating subform, I can't operate at all.

    I understand that, because it's a repeating subform that I need to create an XML schema to do this, but also can not know for the life of me how to create the schema. I read tons of tutorials, but no idea how to apply it to my specific needs. I've been able to find only info on how to bind the data source once it's been created.

    I would be eternally grateful if someone could help out me.

    Thank you!

    I edited your form and put it here.

    Here's what I did:

    • Script inserted into your box renamed someone who mask/displays the purchase order / sales quotation
    • I have included a script object with a function I wrote to transfer data from as named fields/subforms from one section to another
    • Inserted a few fields in your table of purchase order

    What you need to do is to complete the development of your purchase order table. Make sure that the common fields between the quote and purchase tables have the same name in order to transfer data.

    No necessary schema.

    Kyle

  • reposition a movieclip on the stage with the coordinates of an xml

    Hello I am new on this forum and somewhat a beginner with actionscript. what I try to do is to reposition a movieclip already with the coordinates that will be in an XML file on my server. But so far no luck.

    That's what I have for AS3

    var my_x:Number;

    var my_y:Number;

    var myCoord:XML;

    sample_mc.x = my_x;

    sample_mc.y = my_y;

    var myXMLLoader:URLLoader = new URLLoader();

    myXMLLoader.load (new URLRequest ("coords.xml"));

    myXMLLoader.addEventListener (Event.COMPLETE, processXML);

    processXML function (e: Event): void {}

    var myXML:XML = new XML (e.target.data);

    myCoord = myXML.position.pos1;

    my_x = myCoord.@XPOSITION;

    my_y = myCoord.@YPOSITION;

    }

    And the XML file

    < location >

    < WHICH pos1 = POSITIONY "100" = "55" >

    < /pos1 >

    < stop >

    Let me know if anyone can correct what I am doing wrong, please.

    use:

    var my_x:Number;

    var my_y:Number;

    var myCoord:XML;

    sample_mc.x = my_x;

    sample_mc.y = my_y;

    var myXMLLoader:URLLoader = new URLLoader();

    myXMLLoader.load (new URLRequest ("coords.xml"));

    myXMLLoader.addEventListener (Event.COMPLETE, processXML);

    processXML function (e: Event): void {}

    var myXML:XML = new XML (e.target.data);

    myCoord = myXML.pos1;

    my_x = Number (myCoord.@XPOSITION);

    my_y = Number (myCoord.@YPOSITION);

    }

  • Cannot add movieclip to the stage

    Hi, I can not add movieclip on stage. Here is the code:

    package
    {
    import flash.display. *;

    Game/public class extends MovieClip
    {
    private var s1:ScrollPlatform = new ScrollPlatform();

    public void main()
    {

    addChild (s1);
    S1.x = 0;
    }
    }
    }

    I have it in the first picture of the scenario:

    game: var = new game Game();
    Game.main ();

    Help, please. I am a newbie.

    You class Game has no entrepreneur. You must have:

    public function Game():void {
         ...
    }
    

    Perhaps your function main() is supposed to beGame()

    So either set the game as your document class (game becomes your main timeline), or create an instance and add to the scene:

    var game:Game = new Game();
    addChild(game);
    
  • Count how many movieclip to the stage

    Hi all

    I have these specific movieclips that I can't count. They are all an instance of mc_invis_table and they each have an instance name: mc_invis_table_1, mc_invis_table_2, mc_invis_table_3 ... and so on... until mc_invis_table_18.

    How they rely on the number of instance of mc_invis_table scene?

    -Zainuu

    Try:

    var: sum: uint = 0;

    for (var i: uint; i)<>
    {
    var nameofMc:String is getChildAt (i) .name;.
    If (nameofMc.Slice (0.15) == "mc_invis_table_")
    {
    sum ++;
    }
    }

    trace (Sum);

  • How to target the movieclip on the stage of cutom class

    This is the code and the clips are target1_mc & target2_mc

    package {}
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.text.TextField;


    public class recipeMC extends MovieClip {}

    private var startX:Number;
    private var startY: Number;
    private var counter: Number = 0;


    public void recipeMC() {}
    this.mouseChildren = false;
    this.buttonMode = true;
    this.addEventListener (MouseEvent.MOUSE_DOWN, Pick-up);
    this.addEventListener (MouseEvent.MOUSE_UP, dropIt);
    }
    private void pickUp(event:MouseEvent):void {}
    this.startDrag (true);
    this.parent.addChild (this);
    this.x = startX;
    startY = this.y;

    }
    private void dropIt(event:MouseEvent):void {}
    this.stopDrag ();

    If (this.hitTestObject (target1_mc)
    || this.hitTestObject (target2_mc)) {}
    this.removeEventListener (MouseEvent.MOUSE_DOWN, Pick-up);
    this.removeEventListener (MouseEvent.MOUSE_UP, dropIt);
    this.buttonMode = false;
    This.x = myTarget.x;
    This.y = myTarget.y;
    counter ++;
    } else {}
    reply_txt. Text = "Try Again!";
    This.x = startX;
    This.y = startY;
    }

    }
    }
    }

    If target1_mc, for example, is on the main timeline (and this instance of the class is added to the display list), use:

    MovieClip (root) .target1_mc

Maybe you are looking for