AS3 remove FreeTransformManager move Easing - actionscript-3

I'm using the FTS of Ryan Tan, by default it got an easing when you move the object, i searched in the code but i couldn't find how to remove it!
This is my set up
var fts:FreeTransformManager = new FreeTransformManager(false);
fts.dragArea = new Rectangle(0,0,3400,1000);
fts.boundingBoxOutlineThickness = 10;
fts.handleRadius = 0;
fts.handleOutlineThickness = 0;
fts._boundingBoxOutlineColor = 0xff9933;
fts.handleFillColor = 0x33cc33;
fts.buttonMode = true;

I Solved it by changing all Stage.mouseX by me.mouseX in the freeTransformManager.as

Related

AS3 removing dynamically created child movieclips

I'm fairly new to AS3. Anyways, I'm try to remove a dynamically created child movieclip when clicked on. When a dirt block is clicked on, which is a child movieclip of 'world' I want to remove it.
I've tried various ways of removing it using removeChild. I've also tried moving the function inside/outside of the for loop that creates the movieclips.
var blockCount:Number = 0;
var blockArray:Array = [];
var world:MovieClip = new World();
world.x = 50;
world.y = 50;
world.name = "world";
addChild(world);
for(var i:Number=1;i<=100;i++){
blockCount++;
var tempGrassBlock:MovieClip = new GrassBlock();
tempGrassBlock.x = i*16;
tempGrassBlock.y = 256;
tempGrassBlock.name = "b"+blockCount;
world.addChild(tempGrassBlock);
tempGrassBlock.addEventListener(MouseEvent.CLICK, removeBlock);
function removeBlock(event:Event){
world.removeChild(getChildByName(event.target.name));
}
}
Thanks for the help.
Try this
function removeBlock(event:Event){
world.removeChild(event.currentTarget as DisplayObject);
}
No function definition should be inside a for. I changed that in your code and rewrited a little below:
var blockCount:Number = 0;
var blockArray:Array = [];
var world:MovieClip = new World();
world.x = 50;
world.y = 50;
world.name = "world";
addChild(world);
for(var i:Number=1;i<=100;i++){
blockCount++;
var tempGrassBlock:MovieClip = new GrassBlock();
tempGrassBlock.x = i*16;
tempGrassBlock.y = 256;
tempGrassBlock.name = "b"+blockCount;
world.addChild(tempGrassBlock);
tempGrassBlock.addEventListener(MouseEvent.CLICK, removeBlock);
}
function removeBlock(event:MouseEvent){
trace("Is click really working? This target name is " + event.currentTarget.name);
world.removeChild(event.currentTarget));
}

as3 text-wrap problems, firefox, mac

So, I've built a little site for a client that doesn't seem to have any problems for me. I post it, and my client reports to me that some of the text is being clipped off in the text fields. I try to recreate the problem on my pc with chrome and firefox, but everything works fine. But he sends me screenshots from his mac with firefox, and sure enough they are being clipped. He claims its only fire-fox, and it is not a factor of window size. so here are the images to show whats going on:
Further most right words should be "Alabama" & "growing"
and here is the code that produces that text (descTextNew is the culprit here):
nameText.text = names[elementNumber];
nameText.autoSize = "center";
nameText.x = object.x + (.5 * videoWidth) - (.5 * nameText.width);
nameText.y = object.y + videoHeight + 8;
nameText.background = true;
nameText.backgroundColor = 0x000000;
textStyling.color = 0xFFFFFF;
textStyling.size = 20;
textStyling.font = myFont.fontName;
textStyling.letterSpacing = 3;
textStyling.align = "center";
nameText.embedFonts = true;
nameText.setTextFormat(textStyling);
container.addChild(nameText);
descTextNew.text = descArrayContent[elementNumber];
descTextNew.y = object.y + videoHeight + nameText.textHeight + margin - 15;
descTextNew.width = nameText.textWidth + 30;
descTextNew.x = object.x + ( (videoWidth - descTextNew.width) / 2 );
descTextNew.wordWrap = true;
descTextNew.autoSize = "left";
descTextNew.background = true;
descTextNew.backgroundColor = 0x000000;
descTextStyling.color = 0xFFFFFF;
descTextStyling.size = Math.round(11 * 1000/stage.stageWidth);
descTextStyling.font = myFont.fontName;
descTextStyling.letterSpacing = .5;
descTextStyling.align = "left";
descTextNew.setTextFormat(descTextStyling);
container.addChild(descTextNew);
Some of these variables are declared as instance variables prior like this:
var names:Array = new Array();
var nameText:TextField = new TextField();
var textStyling:TextFormat = new TextFormat();
var descTextNew:TextField = new TextField();
var descTextStyling:TextFormat = new TextFormat();
var margin:int = 28;
var videoWidth:int = 267;
var videoHeight:int = 150;
arrays names and descArrayContent have the strings "Paul Rollins, Sr." and "Paul Rollins runs a funeral... " added to them at an index number determined by the variable elementNumber. Also object is the image you see in the pic. don't think its necessary to show you that code.
Here's a link if you want to see it in action:
www.footsoldiers.org/test2/
Any ideas what the hell is going on? I don't know where to start.
Have you tried invalidating the control for redraw manually?
this.invalidateDisplayList();
this.invalidateLayering();
this.invalidateLayoutDirection();
this.invalidateProperties();
this.invalidateSize();
I would try to set the .text property after you have set all the other properties.
So try putting the descTextNew.text = descArrayContent[elementNumber] action on the last line.
If this still doesn't fix your problem, I would recommend to also include the descTextNew.multiline = true property.
Good luck!

How to set dynamic locations in an Image using actionscript3.0?

I want to set different locations in an Image, and when I mouse over the location it needs to shows something('box' or 'x' nd 'y' position of the location). How can i achieve this.?
Hope, you want to set some locations in the stage and u want to store something.
If that, your coding is good. here after u can achieve that by using amf-php for back end purpose. php will help u store values in the database. refer google to know about amf-php.
good luck.
not sure wht you are looking for, may be something like that
http://www.oscartrelles.com/archives/dynamic_movieclip_registration_with_as3
Not registration point...
var msgBox:messageBox;//package
var loc:Array = new Array();
for(var i:uint = 0;i<20;i++)
{
for(var j:uint = 0;j<14;j++)
{
spr = new Sprite();
spr.graphics.beginFill(0xaaaaaa,.1);
spr.graphics.drawCircle(0,0,10);
spr.graphics.endFill();
addChild(spr);
loc.push(spr);
spr.x = 30 + i * spr.width * 1.3;
spr.y = 30 + j * spr.height * 1.3;
}
}
for(i=0; i<loc.length;i++)
{
loc[i].name = "unknown "+i;
loc[i].buttonMode = true;
loc[i].addEventListener(MouseEvent.MOUSE_OVER, mouseOverAction);
loc[i].addEventListener(MouseEvent.MOUSE_OUT, mouseOutAction);
}
function mouseOverAction (e:MouseEvent):void
{
msgBox = new messageBox(100,20,6,0xFFFFFF);
addChild(msgBox);
cur_loc_name = new TextField();
cur_loc_name.text = e.target.name;
msgBox.addChild(cur_loc_name);
cur_loc_name.x = 5;
cur_loc_name.y = 1;
msgBox.x = mouseX + 20;
msgBox.y = mouseY + 26;
}
function mouseOutAction (e:MouseEvent):void
{
removeChild(msgBox);
}
Run this code. It will fill the stage with 280 sprites, and each sprite can have diff instance name..
I wants to do this using pixels...or any other way to do?

Unloading a Loader with actionscript 3

Hello and thank you very much for looking at this. I've spent too many hours struggling.
The code below loads a slideshow of four images, along with thumbnails for those images. It works fine.
I've added a button called "invis_button", that when pressed is supposed to remove the 3 loaders that make up the slideshow, using the removeChild command for each loader.
But this is the problem, there are 3 loaders involved in the slide-show. The removeChild command successfully removes one of the loaders (named "loader3"), but not the other two ("container3", and "thumbLoader3"). It returns an error stating "access of undefined property thumbLoader3" or "Container3".
Can someone tell me why this is ? Or better still, how to make that button (invis_button) unload the entire slide-show.
var images3:Array = ["ad_bona1.jpg", "ad_bona2.jpg", "ad_darkhawk1.jpg", "ad_darkhawk2.jpg"];
var thumbX3:Number = -375;
var thumbY3:Number = 220;
var loader3:Loader = new Loader();
loader3.load(new URLRequest("assets/ad_bona1.jpg"));
addChild(loader3);
loader3.alpha = 0;
loadThumbs3();
function loadThumbs3():void
{
var thumbLoader3:Loader;
var container3:Sprite = new Sprite();
addChild(container3);
container3.buttonMode = true;
for(var i3:uint = 0; i3 < images3.length; i3++)
{
thumbLoader3 = new Loader();
thumbLoader3.load(new URLRequest("assets/thumbs/" + images3[i3]));
thumbLoader3.x = thumbX3;
thumbLoader3.y = thumbY3;
thumbX3 += 85;
container3.addChild(thumbLoader3);
thumbLoader3.addEventListener(MouseEvent.CLICK, thumbClicked3);
}
}
function thumbClicked3(event:MouseEvent):void
{
var path3:String = event.currentTarget.contentLoaderInfo.url;
path3 = path3.substr(path3.lastIndexOf("/") + 1);
loader3.load(new URLRequest("assets/" + path3));
}
///PROBLEM BELOW, button removes only "loader3" and not the other two for some reason
invis_button.addEventListener(MouseEvent.CLICK, unload_loaders);
function unload_loaders(event:MouseEvent):void{
removeChild(loader3);
removeChild(thumbLoader3);
removeChild(container3);
}
Not sure if this is the entire reason behind what you're observing... but for starters, "thumbloader3" and "container3" are scoped locally to the loadThumbs3() method, which means once you finish executing the function, Flash's handles to those objects are lost (not to mention being in an entirely different scope)... try creating class-level properties for those two. Once that's done you should be able to successfully remove them from the stage later on.
I hope that you're also properly destroying your objects, and for the sake of brevity you just chose to omit that code above.
I've edited the code you had above & put the properties into the proper scope. (the multiple copies of thumbLoader3 are now collected inside of a vector (specialized array) so that they can be properly addressed when it comes time to destroy them)
I also wrote you a proper destroy method. ;)
I haven't tried it on my own machine, but give it a spin & see how it goes.
var images3:Array = ["ad_bona1.jpg", "ad_bona2.jpg", "ad_darkhawk1.jpg", "ad_darkhawk2.jpg"];
var thumbX3:Number = -375;
var thumbY3:Number = 220;
// begin new instance properties..
// created a new property, allowing you to group (and hold on to) the multiple thumbLoaders
var thumbLoader3Vector:Vector.<Loader> = new Vector.<Loader>();
var container3:Sprite;
// end new instance properties
var loader3:Loader = new Loader();
loader3.load(new URLRequest("assets/ad_bona1.jpg"));
addChild(loader3);
loader3.alpha = 0;
loadThumbs3();
function loadThumbs3():void
{
// this is where container3 used to be declared
container3 = new Sprite();
addChild(container3);
container3.buttonMode = true;
for(var i3:uint = 0; i3 < images3.length; i3++)
{
var tPtr:int = thumbLoader3Vector.length;
thumbLoader3Vector.push(new Loader());
// this is where thumbLoader3 used to be declared & instantiated
thumbLoader3Vector[tPtr].load(new URLRequest("assets/thumbs/" + images3[i3]));
thumbLoader3Vector[tPtr].x = thumbX3;
thumbLoader3Vector[tPtr].y = thumbY3;
thumbX3 += 85;
container3.addChild(thumbLoader3Vector[tPtr]);
thumbLoader3Vector[tPtr].addEventListener(MouseEvent.CLICK, thumbClicked3);
}
}
function thumbClicked3(event:MouseEvent):void
{
var path3:String = event.currentTarget.contentLoaderInfo.url;
path3 = path3.substr(path3.lastIndexOf("/") + 1);
loader3.load(new URLRequest("assets/" + path3));
}
///PROBLEM BELOW, button removes only "loader3" and not the other two for some reason
invis_button.addEventListener(MouseEvent.CLICK, unload_loaders);
function unload_loaders(event:MouseEvent):void{
// since the thumbLoader3 Loaders are children of container3 in the display list, we need to remove them first
for(var $i:uint = 0;$i<thumbLoader3Vector.length;$i++)
{
removeChild(thumbLoader3Vector[$i]);
// also make sure you remove the listener, so that the object will be picked up by garbage collection
thumbLoader3Vector[$i].removeEventListener(MouseEvent.CLICK, thumbClicked3);
}
// and then just set the entire vector to null
thumbLoader3Vector = null;
// remove the loader3 object & set it to null
removeChild(loader3);
loader3 = null;
// remove the container3 object & set it to null
removeChild(container3);
container3 = null;
}

Flash AS3 drop shadows don't show up when changing height & width

In as3 I'm creating a drop shadow, which works fine. But when I change the height or width of the object (mcWhiteBorder) the drop shadow does not appear at all. Any ideas?
var mcWhiteBorder:whiteBorder = new whiteBorder();
var dropShadow:DropShadowFilter = new DropShadowFilter();
dropShadow.distance = 1;
dropShadow.alpha = .2;
dropShadow.blurX = 10;
dropShadow.blurY = 10;
mcWhiteBorder.height = houseXML.height-40;
mcWhiteBorder.width = houseXML.width+5;
mcWhiteBorder.x = houseXML.photoX-10;
mcWhiteBorder.y = houseXML.photoY+20;
mcWhiteBorder.filters = [dropShadow];
addChild(mcWhiteBorder);
I've copied and pasted your code and it seems to work. Sure, I don't know what your library symbol looks like (i just used a gray sqare) and I've replaced the houseXML variable with static values. The code I've tried is the following:
var mcWhiteBorder:whiteBorder = new whiteBorder();
var dropShadow:DropShadowFilter = new DropShadowFilter();
dropShadow.distance = 1;
dropShadow.alpha = .2;
dropShadow.blurX = 10;
dropShadow.blurY = 10;
mcWhiteBorder.height = 200;
mcWhiteBorder.width = 300;
mcWhiteBorder.x = 50;
mcWhiteBorder.y = 50;
mcWhiteBorder.filters = [dropShadow];
addChild(mcWhiteBorder);
It seems to work just fine.. Check your houseXML and see if the values you assign are valid and so on.
I've had some problems in the past with this, also. I've come to the conclusion that it always works if you're adding the filter to the existing filter array, instead of creating a new one, even if it's empty. I'm not really sure why. Your code would be something like:
var mcWhiteBorder:whiteBorder = new whiteBorder();
var tmpFilters:Array = mcWhiteBorder.filters;
var dropShadow:DropShadowFilter = new DropShadowFilter();
dropShadow.distance = 1;
dropShadow.alpha = .2;
dropShadow.blurX = 10;
dropShadow.blurY = 10;
mcWhiteBorder.height = houseXML.height-40;
mcWhiteBorder.width = houseXML.width+5;
mcWhiteBorder.x = houseXML.photoX-10;
mcWhiteBorder.y = houseXML.photoY+20;
tmpFilters.push(dropShadow);
mcWhiteBorder.filters = tmpFilters;
addChild(mcWhiteBorder);
So instead of asigning a filter to the filters property, you're actually adding that filter to the existing ones. I'm curious if that works.
Take note that filters don't work with clips bigger than "certain values", have a look at the comments in this thread...
I'm not seeing any problems syntax-wise.
dropShadow.distance = 1;
dropShadow.alpha = .2;
dropShadow.blurX = 10;
dropShadow.blurY = 10;
That's pretty faded out. Change alpha to 1 or 2 and see if you can see it. Also, you don't seem to be setting the color. I think the default is black. Make sure you're object isn't over something dark and you're just missing it.