<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>David Madsen</title>
	<link>http://mad00000.squidpower.com</link>
	<description>Just another Squidpower.com weblog</description>
	<pubDate>Mon, 28 Aug 2006 18:09:56 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
	<language>en</language>
			<item>
		<title>Flex 2 / ActionScript 3: Extension of Tree that enforces stricter hierarchy for drag &#38; drop.</title>
		<link>http://mad00000.squidpower.com/2006/08/17/flex-2-actionscript-3-extension-of-tree-that-enforces-stricter-hierarchy-for-drag-drop/</link>
		<comments>http://mad00000.squidpower.com/2006/08/17/flex-2-actionscript-3-extension-of-tree-that-enforces-stricter-hierarchy-for-drag-drop/#comments</comments>
		<pubDate>Thu, 17 Aug 2006 21:10:03 +0000</pubDate>
		<dc:creator>mad00000</dc:creator>
		
		<category><![CDATA[Flex 2 / ActionScript 3]]></category>

		<guid isPermaLink="false">http://mad00000.squidpower.com/2006/08/17/flex-2-actionscript-3-extension-of-tree-that-enforces-stricter-hierarchy-for-drag-drop/</guid>
		<description><![CDATA[This is an extension of Tree that doesn&#8217;t allow items to be dropped at a different depth then they were originally. E.g. if an item is at a depth of 4 it can be moved behind or in front of other items at depth 4. It can even be moved from its parent item into [...]]]></description>
			<content:encoded><![CDATA[<p align="left">This is an extension of <code>Tree</code> that doesn&#8217;t allow items to be dropped at a different depth then they were originally. E.g. if an item is at a depth of 4 it can be moved behind or in front of other items at depth 4. It can even be moved from its parent item into another item(A) as long as the depth of A&#8217;s children is 4. The item can never be moved up or down to a different depth.</p>
<p align="left">The <code>dragDropHandler</code> function in Tree has code that prevents dropping a node into one of its descendants. A few lines of code added in the same part would create the additional restrictions. Unfortunately these lines of code need to go into the middle of <code>dragDropHandler</code>&#8217;s code. This prevents an override that first makes a call to the superclass&#8217;s function, then adds additional functionality.</p>
<pre>
<div class='codeBlock150'>&#8230;in dragDropHandler&#8230;
var offset:int = getItemIndex(iterator.current);
var futureDepth:int = getItemDepth(_dropData.parent,
     Math.abs(offset - getItemIndex(_dropData.parent)));
var currentDepth:int = getItemDepth(parent,
     Math.abs(offset - getItemIndex(parent)));
if(_dropData.parent == null)
  futureDepth = 0;
if(parent == null)
  currentDepth = 0;
if (futureDepth != currentDepth) // the parent should only be 1 greater than item depth
  return;
&#8230;</div>
</pre>
<p align="left">To add those lines of code the whole <code>dragDropHandler</code> function need to be copied and placed into the overriding function. This would be fairly easy if ActionScript could inherit private variables/functions or if <code>Tree</code> had more protected variables/functions.</p>
<p align="left">Instead any private function/variable that <code>dragDropHandler</code> uses must also have a local copy in <code>myTree</code>. If that function sets or interacts with other private functions/variables those were also added. Note that, except for one exception, none of these functions actually override functions in the superclass.  Rather they duplicate the same functionality for when <code>myTree</code> needs it.</p>
<p align="left">Unlike the private functions that were duplicated, <code>calculateDropIndex</code> was public. But for some reason an error is thrown  if it is not overridden. This is likely because <code>dragDropHandler </code>originally calls <code>super.calculateDropIndex</code> and not <code>calculateDropIndex</code>.</p>
<p>Here is the code. Note that only the function declarations have been included for most functions. The full code from <code>Tree.as</code> can be substituted at those declarations. The  lines added to <code>dragDropHandler</code> are set out with comments.</p>
<pre>
<div class='codeBlock300'>package edu.byu.mtc.education.assessmenttools.view{

import com.adobe.cairngorm.control.*;
  import edu.byu.mtc.framework.view.*;
  import edu.byu.mtc.education.assessmenttools.control.*;
  import mx.events.*;
  import mx.controls.*;
  import mx.managers.*;
  import flash.geom.Point;
  import mx.collections.*;

public class myTree extends Tree{

protected var _dropData:*;

public function myTree(){
      super();
    }
    override public function calculateDropIndex(event:DragEvent = null):int
    private function updateDropData(event:DragEvent):void
    private function getChildIndexInParent(parent:Object, child:Object):int
    private function getChildren(item:Object, view:Object):ICollectionView
    private function getParentStack(item:Object):Array
    private function getItemIndex(item:Object):int

override protected function dragDropHandler(event:DragEvent):void{
      if (event.isDefaultPrevented())
            return;
      hideDropFeedback(event);
      if (event.dragSource.hasFormat(&#8221;treeItems&#8221;)){
        //we only support MOVE by default
        if (event.action == DragManager.MOVE &amp;&amp; dragMoveEnabled){
          var items:Array = event.dragSource.dataForFormat(&#8221;treeItems&#8221;) as Array;
          //Are we dropping on ourselves?
          if (event.dragInitiator == this){
            // If we&#8217;re dropping onto ourselves or a child of a descendant then dont actually drop
            var dropIndex:* = super.calculateDropIndex(event);
            var index:int;
            var parent:*;
            var parentItem:*;
            var dropParentStack:Array = getParentStack(_dropData.parent);
            dropParentStack.unshift(_dropData.parent); //optimize stack method
            for (var i:int = 0; i &lt; items.length; i++) {
              parent = getParentItem(items[i]);
              index = getChildIndexInParent(parent, items[i]);

//****begin added*************************************
              var offset:int = getItemIndex(iterator.current);
              var futureDepth:int = getItemDepth(_dropData.parent, Math.abs(offset - getItemIndex(_dropData.parent)));
              var currentDepth:int = getItemDepth(parent, Math.abs(offset - getItemIndex(parent)));
              if(_dropData.parent == null)
              futureDepth = 0;
              if(parent == null)
                currentDepth = 0;
              // the parent should only be 1 greater than item depth
              if (futureDepth != currentDepth)
                return;
//****end added**************************************
              for each (parentItem in dropParentStack)
              {
                //we dont want to drop into one of our own sets of children
                if (items[i] == parentItem)
                  return;
              }
              //we remove before we add due to the behavior
              //of structures with parent pointers like e4x
              removeChildItem(parent, items[i], index);
              //is the removed item before the drop location?
              if (parent == _dropData.parent &amp;&amp; index &lt; _dropData.index) {
                addChildItem(_dropData.parent, items[i], _dropData.index - 1);
              }
              else {
                addChildItem(_dropData.parent, items[i], _dropData.index);
              }
            }
          }
        }
      }
    }
  }
}</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mad00000.squidpower.com/2006/08/17/flex-2-actionscript-3-extension-of-tree-that-enforces-stricter-hierarchy-for-drag-drop/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Launching flex applications in the stand alone player.</title>
		<link>http://mad00000.squidpower.com/2006/08/15/launching-flex-applications-in-the-stand-alone-player/</link>
		<comments>http://mad00000.squidpower.com/2006/08/15/launching-flex-applications-in-the-stand-alone-player/#comments</comments>
		<pubDate>Tue, 15 Aug 2006 22:41:06 +0000</pubDate>
		<dc:creator>mad00000</dc:creator>
		
		<category><![CDATA[Flex Builder]]></category>

		<guid isPermaLink="false">http://mad00000.squidpower.com/2006/08/15/launching-flex-applications-in-the-stand-alone-player/</guid>
		<description><![CDATA[By default flex builder launches its applications through the system default browser. This can easily be changed to launch projects in the stand alone player. This of course assumes that you have the stand alone player installed.
To change these settings go to the &#8216;Run&#8217; menu and select &#8216;Run&#8230;&#8217;. This will bring up a dialog box [...]]]></description>
			<content:encoded><![CDATA[<p>By default flex builder launches its applications through the system default browser. This can easily be changed to launch projects in the stand alone player. This of course assumes that you have the stand alone player installed.</p>
<p>To change these settings go to the &#8216;<u>R</u>un&#8217; menu and select &#8216;Ru<u>n</u>&#8230;&#8217;. This will bring up a dialog box as shown in the attached screen shot. To start make sure there is a configuration under &#8216;Flex Application&#8217; in the left panel. It should be named after the current project. If not, right click on &#8216;Flex Application&#8217; and create a new configuration.</p>
<p><a href="http://mad00000.squidpower.com/files/2006/08/eclipserunsettings.JPG"><img src="../files/2006/08/eclipserunsettings.JPG" alt="run settings" height="80" width="131" /></a></p>
<p>Once the configuration is complete you can edit its properties. Under the main tab in the right panel, make sure the project you want is selected and that the appropriate application file is specified. Now uncheck &#8216;<u>U</u>se defaults&#8217;. Click &#8216;<u>B</u>rowse&#8230;&#8217; next to the <u>D</u>ebug text area. This should open up the current project&#8217;s bin folder. From there you can select the .swf version of you application file. Do the same for <u>R</u>un and that is it.</p>
<p>Now when ever you run this project it will launch in the stand alone flash player.</p>
]]></content:encoded>
			<wfw:commentRss>http://mad00000.squidpower.com/2006/08/15/launching-flex-applications-in-the-stand-alone-player/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
