controlling depth of objects - SOLVED
Posted: 15 March 2008 10:01 AM   [ Ignore ]
Rank
Joined  2008-03-15
Total Posts:  4
New Member

hi all

I’m working on an diagramming app… it’s nearly done (surprising as I’m new to flash and this was done over the last week :-D)

see attached (and don’t worry the interface is knocked together for testing i have plans to make it prettier)...it might make my explanation a little clearer

basically my problem is with depth when a shape(the diagram shapes) is dragged on to the personal territory (the area next to keyboard) it gains focus and sits on top of it but when the keyboard or one of my horrible looking buttons is pressed the personal territory gains focus and is brought to the front...i don’t want this to happen...the shapes should always sit over the top of the territory.

i have a similar issue with the connecting lines are applied to the shapes over the top of the shape… so the shape has to be brought into focus to hide the end of the line when i want them to be inserted behind the shapes.

i looked through the code and couldn’t find anything obvious on how to control the depth etc… and being new to this doesn’t help either

could anyone point me in the right direction?
any help would be much appreciated!

thanks
Tim

Image Attachments
diaTouch.jpg
Profile
 
 
Posted: 15 March 2008 12:19 PM   [ Ignore ]   [ # 1 ]
Rank
Joined  2008-03-15
Total Posts:  4
New Member

oh i should probably mention that all the diagram shapes andpersonal territories extend the physical class

Profile
 
 
Posted: 15 March 2008 12:48 PM   [ Ignore ]   [ # 2 ]
Rank
Joined  2008-03-15
Total Posts:  4
New Member

ok little bit of google and some guesswork… PROBLEM SOLVED

for reference if you want to do this

on personal territory (the one i don’t want to jump to the front)

override the function handleBlobCreated() of Physical class
take the code from the Physical class and comment out the last three lines like so

override public function handleBlobCreated(id:intmx:Numbermy:Number)
{
    
var blobinf:Object getBlobInfo(id);
    if(
blobinf.clicked)
    
{
        blobinf
.origRelativePt = new Point(mxmy);            
                
//        parent.swapChildrenAt(parent.getChildIndex(this), parent.numChildren-1);

        //var p:DisplayObjectContainer = parent; 
        //p.removeChild(this);
        //p.addChild(this);
    
}
}

this worked perfect for me… maybe this should be added as a boolean property?

Profile
 
 
Posted: 16 March 2008 10:36 PM   [ Ignore ]   [ # 3 ]
Avatar
RankRankRankRank
Joined  2006-11-09
Total Posts:  1499
Administrator

Hey Tim,

Yea it looks like you found the right code, as for the boolean your 100% right. Physical is a rather new class, so it doesn’t have all the features of our old Rotateable/Scalable class.

If you wanted to make a boolean statement it would look something like this…

// Make a class member variable to control depth swapping upon click
public var bringToFront:Boolean "true";

override public function handleBlobCreated(id:intmx:Numbermy:Number)
{

var blobinf:Object getBlobInfo(id);
if(
blobinf.clicked)
{
blobinf
.origRelativePt = new Point(mxmy);

if(
bringToFront)
{
parent
.swapChildrenAt(parent.getChildIndex(this), parent.numChildren-1);
var 
p:DisplayObjectContainer parent;
p.removeChild(this);
p.addChild(this);
}//END Bring to Front
}//END Clicked
}

Then on the object you want to NOT bring to the front you could change the value of the public boolean var like so.

thePhysicalObject = new PhysicalObject();
thePhysicalObject.bringToFront "false";
addChild(PhysicalObject);

Glad you are enjoying AS3, and your app is looking really promising. I hope you get to show us the results, I always wanted a MT mind mapping application.

Please let us know if you have any more troubles smile

 Signature 

~

Profile
 
 
Posted: 17 March 2008 05:05 AM   [ Ignore ]   [ # 4 ]
Rank
Joined  2008-03-15
Total Posts:  4
New Member

Hi

Thanks for the info.

i’m doing the app for a university project. once it’s done you guys are more than welcome to it.

it is pretty messy code atm i haven’t done object-oriented code in quite a while and things like the keyboard are hard coded (which i know is far from good...a little bit of xml and actionscript would be better) but time is now my biggest enemy with the work.

I’ve found this pretty entertaining so far and will hopefully help contribute once i’m done with uni (only a couple of months)...need to improve my hardware though...the screen is the bare minimum grin

also i have made a number of changes to Seth Sandlers class LockMedia - from grepping through the directory no one has made use of it aside from me, but i think it is a pretty useful class (a user can grab their personal space and move it around and any shapes currently owned (ie colliding with it) follow it.

original code

public class LockMedia {

        
public static function lockMediaFromCanvas(newParent:DisplayObjectoldParent:DisplayObjectthisChild:DisplayObjectlocked:Boolean false{

            
if (locked == true{

                
//Set Adjust position
                
var newPos CoordinateTools.localToLocal(thisChildnewParent);
                
                
//Adjust scale
                
thisChild.scaleX oldParent.scaleX thisChild.scaleX;
                
thisChild.scaleY oldParent.scaleY thisChild.scaleY;
                
                
//Add to new parent (pop off of current parent/canvas);
                
newParent.addChild(thisChild);
                
                
//Adjust rotation
                
thisChild.rotation += oldParent.rotation;
                
                
//Adjust position
                
thisChild.newPos.x;
                
thisChild.newPos.y;
            
}
            
            
if (locked == false{
                
                
//Adjust scale
                
thisChild.scaleX thisChild.scaleX/oldParent.scaleX;
                
thisChild.scaleY thisChild.scaleY/oldParent.scaleX;
                
                
//Set Adjust position
                
var newPos CoordinateTools.localToLocal(thisChildoldParent);
                
thisChild.= (newPos.x);
                
thisChild.= (newPos.y);
                
                
//Adjust rotation
                
thisChild.rotation -= oldParent.rotation;
                
                
//Add back to old parent (pop back onto old parent/canvas);
                
oldParent.addChild(thisChild);
            
}
        }
    }
}

for my application i found that the scaling and rotation had not worked as expected… i am unsure whether it is because the code is untested/wrong or because he wrote it with something different in mind.

my version

package app.core.action{

    import flash
.display.Sprite;
    
import flash.display.*;
    
import flash.geom.Point;
    
import app.core.utl.CoordinateTools;


    public class 
LockMedia {

        
public static function lockMediaFromCanvas(newParent:DisplayObjectoldParent:DisplayObjectthisChild:DisplayObjectlocked:Boolean false{

            
if (locked == true{

                
//Set Adjust position
                
var newPos CoordinateTools.localToLocal(thisChildnewParent);
                
                
//Adjust scale
                
thisChild.scaleX thisChild.scaleX newParent.scaleX;
                
thisChild.scaleY thisChild.scaleY newParent.scaleY;
                
                
//Add to new parent (pop off of current parent/canvas);
                
newParent.addChild(thisChild);
                
                
//Adjust rotation
                
thisChild.rotation -= newParent.rotation;
                
                
//Adjust position
                
thisChild.newPos.x;
                
thisChild.newPos.y;
            
}
            
            
if (locked == false{
                
                
//Adjust scale
                
thisChild.scaleX thisChild.scaleX newParent.scaleX;
                
thisChild.scaleY thisChild.scaleY newParent.scaleY;
                
                
//Set Adjust position
                
var newPos CoordinateTools.localToLocal(thisChildoldParent);
                
thisChild.= (newPos.x);
                
thisChild.= (newPos.y);
                
                
//Adjust rotation
                
thisChild.rotation += newParent.rotation;
                
                
//Add back to old parent (pop back onto old parent/canvas);
                
oldParent.addChild(thisChild);
            
}
        }
    }
}

i haven’t tested this with the scenario of the oldParent having a scale X/Y other than 1.

my question is how would i contribute this version to the community would i make it my own class and submit it along side his or would i suggest replacing his (last thing i want to do is step on someone’s toes...especially if the code is correct for his particular application). i have never done any contributions to a project, so i don’t really know the dynamics of working in a community (also haven’t really used svn but i’m sure that’s easy enough to understand).

Profile