VSC Formatter Implementation no effect - visual-studio-code

Issue Type: Bug
Launch Extension
Right click Reformat file (.items file from openhab)
VS Code version: Code 1.47.0
OS version: Darwin x64 19.5.0
Hey guys,
With the following implementation nothing happens when saving the file (format on save enabled) or when reformatting the file with a right click. I tried a lot of other solutions but none of them worked. I hope you can help me.
export function activate(context: vscode.ExtensionContext) {
vscode.languages.registerDocumentFormattingEditProvider("openhab", {
provideDocumentFormattingEdits(document: vscode.TextDocument, options: vscode.FormattingOptions): vscode.TextEdit[] {
var range = getDocumentRange(document);
var content = document.getText(range);
var result: vscode.TextEdit[] = [];
var formatted = formatItemFile();
//if (formatted) {
// result.push(new vscode.TextEdit(range, formatted));
//}
return formatted;
},
});
}
export function formatItemFile(): vscode.TextEdit[] {
var result: vscode.TextEdit[] = [];
// Get the section lengths of each line with an item in it.
// Only execute if there's an active text editor
if (!vscode.window.activeTextEditor) {
return result;
}
// Define the basic vscode variables
let doc = vscode.window.activeTextEditor.document;
let editor = vscode.window.activeTextEditor;
let currentPos = editor.selection.active;
let newPos: vscode.Position;
let itemArray: Array<Item>;
itemArray = new Array();
// Get the format configuration settings
let config = vscode.workspace.getConfiguration("oh-alignment-tool");
let preserveWhitespace = config.preserveWhitespace;
// Reset the comment tracker
isInBlockComment = false;
// Clear the file in case of line-by-line item definitions
for (let index = 0; index < doc.lineCount; index++) {
// Get Position at the beginning of the current line and start a selection
newPos = currentPos.with(index, 0);
editor.selection = new vscode.Selection(newPos, newPos);
// Get Text of current line and check if there is a comment in it
let lineText = doc.lineAt(newPos.line);
var comment = doc.getWordRangeAtPosition(newPos.with(newPos.line, 0), REGEX_COMMENT);
var blockComment = doc.getWordRangeAtPosition(newPos.with(newPos.line, 0), REGEX_START_BLOCKCOMMENT);
var endBlockComment = doc.getWordRangeAtPosition(newPos.with(newPos.line, 0), REGEX_END_BLOCKCOMMENT);
// If line is empty or contains a comment continue to the next line
if (lineText.text.length === 0 || lineText.isEmptyOrWhitespace) {
continue;
} else if (comment) {
continue;
} else if (blockComment && endBlockComment) {
isInBlockComment = false;
continue;
} else if (blockComment) {
isInBlockComment = true;
continue;
} else if (endBlockComment) {
isInBlockComment = false;
continue;
} else if (isInBlockComment) {
continue;
}
// Default these to empty. They will be changed
// if they exist in the item definition
let itemType = "";
let itemName = "";
let itemLabel = "";
let itemIcon = "";
let itemGroup = "";
let itemTag = "";
let itemChannel = "";
let itemComment = "";
// Check if there is leading Whitespace. If Yes add one in size of a tab.
let leadingWhiteSpace = lineText.firstNonWhitespaceCharacterIndex;
if (preserveWhitespace === false) {
leadingWhiteSpace = 0;
}
// Discover item Type
// Count Whitespace or tabs at the begin of the line
newPos = newPos.with(newPos.line, newPos.character + utils.countWhitespace(doc, newPos));
var wordRange = doc.getWordRangeAtPosition(newPos, REGEX_ITEM_TYPE);
if (wordRange && wordRange.isSingleLine) {
itemType = doc.getText(wordRange);
highestTypeLength = itemType.length > highestTypeLength ? itemType.length : highestTypeLength;
newPos = newPos.with(newPos.line, newPos.character + itemType.length);
newPos = newPos.with(newPos.line, newPos.character + utils.countWhitespace(doc, newPos));
// Discover item Name
var itemNameRange = doc.getWordRangeAtPosition(newPos, REGEX_ITEM_NAME);
if (itemNameRange && itemNameRange.isSingleLine) {
itemName = doc.getText(itemNameRange);
highestNameLength = itemName.length > highestNameLength ? itemName.length : highestNameLength;
newPos = newPos.with(newPos.line, newPos.character + itemName.length);
newPos = newPos.with(newPos.line, newPos.character + utils.countWhitespace(doc, newPos));
}
}
// Must have a type and name to continue
if (itemType.length === 0 || itemName.length === 0) {
continue;
}
// Discover item Label
let itemLabelRange = doc.getWordRangeAtPosition(newPos, REGEX_ITEM_LABEL);
if (itemLabelRange && itemLabelRange.isSingleLine) {
itemLabel = doc.getText(itemLabelRange);
highestLabelLength = itemLabel.length > highestLabelLength ? itemLabel.length : highestLabelLength;
newPos = newPos.with(newPos.line, newPos.character + itemLabel.length);
newPos = newPos.with(newPos.line, newPos.character + utils.countWhitespace(doc, newPos));
}
// Discover item Icon
let itemIconRange = doc.getWordRangeAtPosition(newPos, REGEX_ITEM_ICON);
if (itemIconRange && itemIconRange.isSingleLine) {
itemIcon = doc.getText(itemIconRange);
highestIconLength = itemIcon.length > highestIconLength ? itemIcon.length : highestIconLength;
newPos = newPos.with(newPos.line, newPos.character + itemIcon.length);
newPos = newPos.with(newPos.line, newPos.character + utils.countWhitespace(doc, newPos));
}
// Discover item Group
let itemGroupRange = doc.getWordRangeAtPosition(newPos, REGEX_ITEM_GROUP);
if (itemGroupRange && itemGroupRange.isSingleLine) {
itemGroup = doc.getText(itemGroupRange);
highestGroupLength = itemGroup.length > highestGroupLength ? itemGroup.length : highestGroupLength;
newPos = newPos.with(newPos.line, newPos.character + itemGroup.length);
newPos = newPos.with(newPos.line, newPos.character + utils.countWhitespace(doc, newPos));
}
// Discover item Tag
let itemTagRange = doc.getWordRangeAtPosition(newPos, REGEX_ITEM_TAG);
if (itemTagRange && itemTagRange.isSingleLine) {
itemTag = doc.getText(itemTagRange);
highestTagLength = itemTag.length > highestTagLength ? itemTag.length : highestTagLength;
//console.log("Tag: " + itemTag);
newPos = newPos.with(newPos.line, newPos.character + itemTag.length);
newPos = newPos.with(newPos.line, newPos.character + utils.countWhitespace(doc, newPos));
}
// Discover item Channel
let itemChannelRange = doc.getWordRangeAtPosition(newPos, REGEX_ITEM_CHANNEL);
if (itemChannelRange && itemChannelRange.isSingleLine) {
itemChannel = doc.getText(itemChannelRange);
highestChannelLength = itemChannel.length > highestChannelLength ? itemChannel.length : highestChannelLength;
newPos = newPos.with(newPos.line, newPos.character + itemChannel.length);
newPos = newPos.with(newPos.line, newPos.character + utils.countWhitespace(doc, newPos));
}
// Discover comment at end of line
let itemCommentRange = doc.getWordRangeAtPosition(newPos, REGEX_EOL_COMMENT);
if (itemCommentRange && itemCommentRange.isSingleLine) {
itemComment = doc.getText(itemCommentRange);
newPos = newPos.with(newPos.line, newPos.character + itemComment.length);
newPos = newPos.with(newPos.line, newPos.character + utils.countWhitespace(doc, newPos));
}
// Add the new item to the itemArray
itemArray.push(new Item(index, leadingWhiteSpace, itemType, itemName, itemLabel, itemIcon, itemGroup, itemTag, itemChannel, itemComment));
}
// Convert the column lengths to tabs
highestTypeLength = utils.generateTabFromSpaces(highestTypeLength);
highestNameLength = utils.generateTabFromSpaces(highestNameLength);
highestLabelLength = utils.generateTabFromSpaces(highestLabelLength);
highestIconLength = utils.generateTabFromSpaces(highestIconLength);
highestGroupLength = utils.generateTabFromSpaces(highestGroupLength);
highestTagLength = utils.generateTabFromSpaces(highestTagLength);
highestChannelLength = utils.generateTabFromSpaces(highestChannelLength);
// Insert the newly formatted items
itemArray.forEach(function (item) {
newPos = currentPos.with(item.line, 0);
editor.selection = new vscode.Selection(newPos, newPos);
let reformattedItem = formatItem(item);
if (reformattedItem !== "") {
let selection = new vscode.Range(newPos, newPos.with(newPos.line, doc.lineAt(newPos.line).text.length));
result.push(new vscode.TextEdit(selection, reformattedItem));
}
});
// Apply all clean and formatting Edits
//textWorkEdit.set(doc.uri, textTextEdits);
//await vscode.workspace.applyEdit(textWorkEdit);
return result;
}

Related

get_value of a feature in IFeatureCursor

I'm trying to read the attribute "POSTCODE" of the features in IFeatureCursor. The FID was successful read but the "POSTCODE" was failed. The runtime error 'An expected Field was not found or could not be retrieved properly. Appreciate your advise. Paul
private void test2(IFeatureCursor pFeatc1)
{
IFeature feature = null;
IFields pFields;
int ctcur = 0;
while ((feature = pFeatc1.NextFeature()) != null)
{
pFields = feature.Fields;
int indxid = pFields.FindField("FID");
int indxpost = pFields.FindField("POSTCODE");
object valu = feature.get_Value(indxid);
string valupost = feature.get_Value(indxpost);
string aValu = Convert.ToString(valu);
Debug.WriteLine("FID: " + aValu + " Postcode: " + valupost);
ctcur++;
feature = pFeatc1.NextFeature();
}
MessageBox.Show("count cursor = " + ctcur);
}
I have modified the program and successfully read the feature attribute 'POSTCODE'. I have added IFeatureClass.Search(queryFilter, true) to search the feature again by FID and save in a cursor then use the 'feature.get_Value' to read the attribute. Please see my updated code below. Thanks.
private void test2(IFeatureCursor pFeatc1)
{
IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;
IMap map = mxdoc.FocusMap;
IFeatureLayer flayer;
IMaps pMaps = mxdoc.Maps;
for (int i = 0; i <= pMaps.Count - 1; i++)
{
map = pMaps.get_Item(i);
IEnumLayer pEnumLayer = map.get_Layers(null, true);
pEnumLayer.Reset();
ILayer pLayer = pEnumLayer.Next();
while (pLayer != null)
{
if (pLayer.Name == "AddrKey")
{
Debug.WriteLine("Layer: " + pLayer.Name);
flayer = (IFeatureLayer)pLayer;
IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
IFeature feature = null;
IFields pFields;
while ((feature = pFeatc1.NextFeature()) != null)
{
pFields = feature.Fields;
int indx = pFields.FindField("FID");
object valu = feature.get_Value(indx);
string sFID = Convert.ToString(valu);
IQueryFilter queryFilter = new QueryFilter();
queryFilter.WhereClause = ("FID = " + sFID);
Debug.WriteLine("FID: " + sFID);
queryFilter.SubFields = "POSTCODE";
int fieldPosition = pFeatureClass.FindField("POSTCODE");
IFeatureCursor featureCursor = pFeatureClass.Search(queryFilter, true);
while ((feature = featureCursor.NextFeature()) != null)
{
MessageBox.Show(feature.get_Value(fieldPosition));
}
feature = pFeatc1.NextFeature();
}
}
pLayer = pEnumLayer.Next();
}
}
}

VSCode language extension with hierarchical Outline, DocumentSymbol

I'm trying to get outline working with a custom language in VScode. I have the below code but I feel like it is slow because of the way I find a range in class. Are there better ways to find the range and assign children. I've thought about just keeping track of the depth of the brackets and assigning all functions/methods/classes in higher depths into the last item of previous depth.
It was based off of this answer.
class JSLDocumentSymbolProvider implements vscode.DocumentSymbolProvider {
public provideDocumentSymbols(document: vscode.TextDocument,
token: vscode.CancellationToken): Thenable<vscode.DocumentSymbol[]> {
return new Promise((resolve, reject) => {
var symbols: vscode.DocumentSymbol[] = [];
var depth = 0;
for (var i = 0; i < document.lineCount; i++) {
var line = document.lineAt(i);
var txt = line.text;
var ltxt = txt.toLowerCase();
let open_brackets = ltxt.match(/\(/g) || [];
let close_brackets = ltxt.match(/\)/g) || [];
// console.log(ltxt)
// console.log(open_brackets, close_brackets)
//console.log(i, open_brackets.length, close_brackets.length)
depth += open_brackets.length - close_brackets.length;
//console.log(depth);
if (ltxt.includes("define class(")) {
let sname = txt.trim().substr(14, txt.trim().length - 16); //this is hard coded right now but it's kind of working
let detail = "ARGS:x, y returns z";
let start_pos = new vscode.Position(i, 0);
let n_bracket = 1;
let i_char = 0;
//let children: vscode.DocumentSymbol[] = []
let ds = new vscode.DocumentSymbol(sname, detail, vscode.SymbolKind.Class, line.range, line.range);
for(var i_line = i; n_bracket > 0; i_line++){
let class_line = document.lineAt(i_line);
let mtxt = class_line.text;
let ic;
if(i == i_line) ic = 16;
else ic = 0;
for(i_char = ic; i_char < mtxt.length; i_char++){
if(mtxt[i_char] === "(") n_bracket++;
else if(mtxt[i_char] === ")") n_bracket--;
if(n_bracket === 0) break
}
if (/(\w[\w\d\s]*)=\s*method\({((?:\s*(?:\w[\w\d\s]*)(?:=[^,]*)?,?\s*)*)},/i.test(mtxt)) {
let result = mtxt.match(/(\w[\w\d\s]*)=\s*method\({((?:\s*(?:\w[\w\d\s]*)(?:=[^,]*)?,?\s*)*)},/i)!;
let mname = result[1].trim();
let m_details = ""
if(result.length == 3){
m_details = result[2].trim();
}
ds.children.push(new vscode.DocumentSymbol(mname, m_details, vscode.SymbolKind.Method, class_line.range, class_line.range));
}
if(n_bracket === 0) break
}
let end_pos = new vscode.Position(i_line, i_char);
let rng = new vscode.Range(start_pos, end_pos);
ds.range = rng;
//ds.children = children;
symbols.push(ds);
}
else if (/(\w[\w\d\s]*)=\s*function\({((?:\s*(?:\w[\w\d\s]*)(?:=[^,]*)?,?\s*)*)},/.test(ltxt)) {
let result = txt.match(/(\w[\w\d\s]*)=\s*function\({((?:\s*(?:\w[\w\d\s]*)(?:=[^,]*)?,?\s*)*)},/i)!;
let sname = result[1].trim();
let detail = "";
if(result.length == 3){
detail = "(" + result[2].trim() + ")";
}
symbols.push(new vscode.DocumentSymbol(sname, detail, vscode.SymbolKind.Function, line.range, line.range));
}
}
resolve(symbols);
});
}
}

after effects - selecting render queue items via script

i'm looking for a way to select items in the render queue via script.
i'm creating a listBox that contains all the RQ items ( i need to list them in a simpler way then the RQ window, and i'm keeping the index number of each item), and i want to select from that list items and select them in the RQ.
ideas?
thanks
Dror
try{
function createUserInterface (thisObj,userInterfaceString,scriptName){
var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", scriptName,
undefined,{resizeable: true});
if (pal == null) return pal;
var UI=pal.add(userInterfaceString);
pal.layout.layout(true);
pal.layout.resize();
pal.onResizing = pal.onResize = function () {
this.layout.resize();
}
if ((pal != null) && (pal instanceof Window)) {
pal.show();
}
return UI;
};
{var res ="group {orientation:'column',\
alignment:['fill','fill'],\
alignChildren:['fill','top'],\
folderPathListbox:ListBox{\
alignment:['fill','fill'],\
properties:{\
multiline:true,\
multiselect:true,\
numberOfColumns:6,\
showHeaders:true,\
columnTitles: ['#','OM','Date','Time', 'Comp Name', 'Render Path']}\
},\
buttonGroup:Group{orientation:'row',\
alignment:['fill','bottom']\
alignChildren:['fill','bottom'],\
buttonPanel: Panel{\
text:'Actions',\
orientation: 'row',\
alignment:['fill','bottom']\
refButton: Button{text:'Refresh'}\
dupButton: Button{text:'Duplicate'}\
selButton: Button{text:'Select in RQ'}\
expButton: Button{text:'Export'}\
}\
searchPanel: Panel{\
text:'Search',\
orientation: 'row',\
searchBox: EditText{text:'search by fileName'},\
searchButton: Button{text:'Search'}, \
}\
}\
}";
}
function listRQ (rqList){
try{
var folderPathListbox = rqList;
var proj = app.project;
var totalRenderQ = proj.renderQueue.numItems;
for(var i= 1; i<=totalRenderQ; i++){
var totalOM= proj.renderQueue.item(i).numOutputModules;
for (var om= 1; om<=totalOM; om++){
var dateList, timeList, curItem;
if (proj.renderQueue.item(i).startTime != null){
var min = proj.renderQueue.item(i).startTime.getMinutes() <10 ? "0"+ proj.renderQueue.item(i).startTime.getMinutes() : proj.renderQueue.item(i).startTime.getMinutes();
var year = proj.renderQueue.item(i).startTime.getFullYear().toString().substr (-2,2);
timeList = (proj.renderQueue.item(i).startTime.getHours()-1)+":" + min;
dateList =proj.renderQueue.item(i).startTime.getDate()+"/"+(proj.renderQueue.item(i).startTime.getMonth()+1)+"/"+year ;
}else{
dateList = "not ";
timeList = "rendered";
}
curItem = folderPathListbox.add ('item', i ); // Column 1
curItem.subItems[0].text = om; // Column 2
curItem.subItems[1].text = dateList.toString(); // Column 3
curItem.subItems[2].text = timeList.toString(); // Column 4
curItem.subItems[3].text = proj.renderQueue.item(i).comp.name; // Column 5
curItem.subItems[4].text = proj.renderQueue.item(i).outputModule(om).file.toString().replace(new RegExp(",","g"), "\r").replace(new RegExp("%20","g"), " ").replace(new RegExp("%5B","g"), "[").replace(new RegExp("%5D","g"), "]"); // Column 6
}
}
}catch(err){alert(err)}
return folderPathListbox;
}
var UI = createUserInterface(this,res,"Better RQ");
var myList = UI.folderPathListbox;
var lsRq = listRQ(myList);
//~ alert(lsRq.toString());
{ // buttons action
UI.buttonGroup.buttonPanel.refButton.onClick = function () {
lsRq.removeAll();
listRQ(myList);
writeLn("all done");
}
UI.buttonGroup.buttonPanel.dupButton.onClick = function () {
var lstSlct = new Array ;
lstSlct = myList.selection;
if ( lstSlct != null){
var totalDup = lstSlct.length;
for (var i= 0; i<totalDup; i++){
var lsId = lstSlct[i].toString();
var dup = parseInt(lsId);
app.project.renderQueue.item(dup).duplicate();
writeLn("duplicated #"+dup);
}
}else{
alert ("select Something");
}
}
UI.buttonGroup.buttonPanel.selButton.onClick = function () {
app.project.renderQueue.showWindow(true) ; //shows the RQ
alert ("selButton");
}
UI.buttonGroup.buttonPanel.expButton.onClick = function () {
// var compName = myList.
alert ("expButton");
}
}
}
catch(err){
alert ("Error at line # " + err.line.toString() + "\r" + err.toString());
}

Calling a function from onEdit() trigger doesn't work

I want to run a function that updates some values when I edit one cell of a column. This line of the trigger works well: dataCell0.setValue(today_date(new Date())[2]);. But this other line updatePercent(); doesn't. But if I call this updatePercent() function from a time based trigger (in Resources), it works well. What is going wrong with this updatePercent() call?
function onEdit(){
var s = SpreadsheetApp.getActiveSheet();
if( ( s.getName() == "mySheet1" ) || (s.getName() == "mySheet2") ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( s.getRange(1, r.getColumn()).getValue() == "PORCENT_TIME") { // If you type a porcent, it adds its date.
var dataCell0 = r.offset(0, 1);
dataCell0.setValue(today_date(new Date())[2]);
updatePercent();
}
}
}
Here the updatePercent function code:
/**
* A function to update percent values accoding to input date.
**/
function updatePercent() {
var sheet = SpreadsheetApp.getActiveSheet();
var column = getColumnNrByName(sheet, "PORCENT_TIME");
var input = sheet.getRange(2, column+1, sheet.getLastRow(), 4).getValues();
var output = [];
for (var i = 0; i < input.length; i++) {
var fulfilledPercent = input[i][0];
Logger.log("fulfilledPercent = " + fulfilledPercent);
var finalDate = input[i][3];
Logger.log("finalDate = " + input[i][3]);
if ( (typeof fulfilledPercent == "number") && (finalDate instanceof Date) ) {
var inputDate = input[i][1]; // Date when input was added.
var restPorcentPen = 100 - fulfilledPercent;
var restantDays = dataDiff(inputDate, finalDate);
var percentDay = restPorcentPen/restantDays;
Logger.log("percentDay = " + percentDay);
var passedTime = dataDiff(inputDate, new Date());
Logger.log("passedTime = " + passedTime);
var passedPorcent = passedTime * percentDay; // How much percent this passed time is?
Logger.log("passedPorcent = " + passedPorcent);
var newPorcent = (fulfilledPercent + passedPorcent);
newPorcent = Math.round(newPorcent * 100) / 100;
Logger.log("newPorcent = " + newPorcent);
var newInputDate = hoje_data(new Date())[2]; // Now update the new input date
// newPorcent = newPorcent.toFixed(2);
output.push([newPorcent, newInputDate]);
sheet.getRange(2, column+1, output.length, 2).setValues(output);
Logger.log(" ");
var column25Dec = getColumnNrByName(sheet, "PORCENT_25DEZ");
var passedTimeSince25Dec = dataDiff(new Date(2013,11,25), new Date()); // Months: January is 0;
var decPercent = (newPorcent - (passedTimeSince25Dec * percentDay)); // .toFixed(2).replace(".", ",");
decPercent = Math.round(decPercent * 100) / 100;
// if (sheet.getRange(output.length+1, column25Dec+1).getValues() == ''){
sheet.getRange(output.length+1, column25Dec+1).setValue(decPercent );
// }
var remainingYears = dataDiffYears(new Date(), finalDate);
sheet.getRange(output.length+1, column).setValue(remainingYears);
}
else {
newPorcent = "Put a final date"
output.push([newPorcent, inputDate]);
sheet.getRange(2, column+1, output.length, 2).setValues(output);
}
if (finalDate instanceof Date){
var remainingYears = dataDiffYears(new Date(), finalDate);
// Logger.log("remainingYears = " + remainingYears);
}
else {
remainingYears = "insert a valid date";
}
sheet.getRange(output.length+1, column).setValue(remainingYears);
}
}
I will guess you're using the new gSheets. Check if it will work in the old-style sheets. The new sheets' onEdit trigger has problems, particularly with getActive.
My problem was in the updatePercent() funciton. Thank you, guys!

drag and drop using Starling

I am have difficulty getting drop and drop to work using Starling with feathers ui.
Here is my code:
function begin(){
var quadx = squareSize/4 + squareSize/8;
var quady = 20;
var quadcounter = 0;
for(var f=0;f<totalsquares;f++){
var sprite:Sprite = new Sprite();
var quad:Quad = new Quad(squareSize, squareSize);
sprite.name = "" + f;
spriteunder.name = "" + f * 1000;
quad.setVertexColor(0, 0x3683ed);
quad.setVertexColor(1, 0x3683ed);
quad.setVertexColor(2, 0x3683ed);
quad.setVertexColor(3, 0x3683ed);
sprite.x=quadx;
sprite.y = quady;
var lv3 = new TextField(squareSize, squareSize, f,"Corpid", 14,0xf1f1f1);
sprite.touchable = true;
quad.touchable = true;
lv3.touchable = false;
sprite.addChild(quad);
sprite.addChild(lv3);
addChild(sprite);
sprite.addEventListener(TouchEvent.TOUCH, touchHandler);
quadx = quadx + squareSize + 1;
quadcounter++;
if(quadcounter == boardWidth){
quadx = squareSize/4 + squareSize/8;
quady = quady + squareSize + 1;
quadcounter = 0;
}
}
}
function touchHandler(e : TouchEvent) : void
{
var touch:Touch = e.getTouch(stage);
var position:Point = touch.getLocation(stage);
var target:Quad = e.target as Quad;
if(touch.phase == TouchPhase.MOVED ){
target.x = position.x - target.width/2;
target.y = position.y - target.height/2;
}
}
The problem is that whenever i run this , its the QUAD child that gets dragged around, not the parent sprite.
What do i change in order to get this to drag correctly.
Perhaps you must start with
var touch:Touch = event.getTouch(this, TouchPhase.BEGAN);
if (touch)
{
//get and lock your target, maybe a trace of your actual target, just to be sure!
}
And then in the MOVED phase, actually drag it.