How can I make a function out of this

Posted on 2009-12-18
Last Modified: 2013-11-11
Im trying to set a mask consisting of 9 squares and want to make a function that creates the squares out of th e following, that works in it self

mask_mc.createEmptyMovieClip("block1", 31);
bgcontainer(mask_mc.block1, 66, 66, 1, 0x000000, 100);
mask_mc.block1._x = 66;
mask_mc.block1._y = 66;

so I created a function looking like this:

function maskBlock(bDepth, bWidth, bHeight, bX, bY){
      var newBlock = "block" +bDepth;
      var newDepth = "3" +bDepth;
      mask_mc.createEmptyMovieClip("block" +bDepth, newDepth);
      mask_mc.newBlock._x = bX;
                     mask_mc.newBlock._y = bY;
      bgcontainer(mask_mc.newBlock, bWidth, bHeight, 1, 0x000000, 100);

but that result in that I get an error saying that there is missing a 'with' action

What is wrong and how should I do it right....
Question by:petersego
    LVL 19

    Accepted Solution

    you've got a couple problems there, mostly with property access

    if you have an object named myObject, and it has a property named myProperty, you can say

    myObject.myProperty or myObject["myProperty"]

    but if you have a variable like this:

    var myString = "myProperty"

    you CAN'T say


    you HAVE to say


    so anyways, i've commented your function - the code's incomplete so I'll fix what i can see but not sure if it'll fix everything
    function maskBlock(bDepth, bWidth, bHeight, bX, bY){
          // so here you've got a string, "block1"
          var newBlock = "block" +bDepth;
          // here you have another string, not a number, like "366", NOT 9 (which is what i think you want)
          // var newDepth = "3" +bDepth;
          // so i'd change that to:
          var newDepth = 3 + bDepth;
          // now the depth is getting a number, and should work...  also, you already have "block" + bDepth in newBlock, so just use that
          // mask_mc.createEmptyMovieClip("block" +bDepth, newDepth);
          // so i'd use this instead, and save it to a variable
          var newMC = mask_mc.createEmptyMovieClip(newBlock, new Depth);
          // and mask_mc.newBlock doesn't exist, so lets use that reference we just made instead
          // mask_mc.newBlock._x = bX;
          // mask_mc.newBlock._y = bY;
          newMC._x = bX;
          newMC._y = bY;
          bgcontainer(newMC, bWidth, bHeight, 1, 0x000000, 100);

    Open in new window


    Author Closing Comment

    Just great.
    The Depth-number I wanted was 31, 32 and so on, but apart from that, I made it work, thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
    I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
    The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
    The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now