|
-
Error #1056: Cannot create property x on String.
Hi everyone. I am new to As3 and I'm getting this error but not sure how to change it from a string. I can 'trace("myfilling: " + myfilling);' and this outputs the instance I want to change the X and Y position of fine but when I try to do myfilling.x = leftBaseX, it throws up the error:
ReferenceError: Error #1056: Cannot create property x on String.
Could someone help please!?
function generateRandomSandwhich() {
while (numFillings < maxFillings) {
var randNum:uint = randomNumber(0, (fillings.length - 1));
if(sandwhichFillings.indexOf(fillings[randNum]) == -1) {
sandwhichFillings.push(fillings[randNum]);
numFillings++;
}
}
for (i = 0; i < sandwhichFillings.length; i++) {
sandwhichToMake.appendText(sandwhichFillings[i]);
if((i+1) < sandwhichFillings.length) {
sandwhichToMake.appendText(", ");
}
//trace(sandwhichFillings[i])
var myfilling = sandwhichFillings[i];
//trace("myfilling: " + myfilling);
myfilling.x = leftBaseX;
myfilling.y = leftBaseY - fillingSpacing;
addChild(myfilling);
}
}
-
Please use [code] or [php] tags to format your code.
You have strings in your fillings array. You should have put the actual filling instances instead. You can either change that, or you can use getChildByName(myFilling) to get the actual instance back to set the x and y properties.
Code:
var realFilling:DisplayObject = getChildByName(myFilling);
realFilling.x = leftBaseX;
realFilling.y = leftBaseY - fillingSpacing;
addChild(realFilling);
This assumes that your fillings have instance names which match the strings, and that they are children of the instance which is running this code.
Also, you misspelled "sandwich".
-
Thank you for your help! It got me on the right tracks and I ended up getting it working by using the following code
Code:
var c:Class = getDefinitionByName(sandwhichFillings[i]) as Class;
var myfilling:MovieClip = new c() as MovieClip;
var myfillingX = leftBaseX;
var myfillingY = baseY - (fillingSpacing*i);
leftSandwichHolder.addChild(myfilling);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|