How can I make a function out of this

Posted on 2009-12-18
Medium Priority
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

moagrius earned 2000 total points
ID: 26081857
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

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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

839 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