Note that there are some explanatory texts on larger screens.

plurals
  1. PODepth issues with multiple instances of a movie clip
    primarykey
    data
    text
    <p>I'm creating an XML custom card game and am at the point of building the deck and making them draggable so the user can drag and drop them on top of another card.</p> <p>I have figured out how to build the deck and put multiple instances of the movie clip that resides in the library, I just cannot figure out a way to make each one of the cards draggable. What currently is happening is the card on top of the deck is the only one that will drag, even if I click on the card below it. I have researched <code>setChildIndex()</code>, but I don't think I am using it correctly.</p> <p>Another issue I'm having is when the user clicks the click_btn (named for testing only) to build the deck it takes a while to build it, can that be sped up any?</p> <p>Then once the user clicks the first card to drag it there is another long wait?</p> <p>Document Class (CardGame.as)</p> <pre><code>package library { import flash.display.*; import flash.events.*; import flash.net.*; public class CardGame extends Sprite { /* * variables */ private var _xml:XML; private var _loader:URLLoader; private var cardArray:Array; private var activity:Activity; /* * constructor */ public function CardGame():void { _loader = new URLLoader(); _loader.addEventListene(Event.COMPLETE,buildArray); _loader.load(new URLRequest("library/card.xml")); click_btn.addEventListener(MouseEvent.CLICK,buildDeck); } /* * metohods */ public function buildArray(e:Event):Array { cardArray = new Array(); _xml = new XML(_loader.data); for(var i=0;i&lt;_xml.card.length();i++) { if(_xml.card.face[i]=="activity") { cardArray.push({id:_xml.card.id[i],face:_xml.card.face[i],category:_xml.card.category[i],point:_xml.card.point[i],value:_xml.card.value[i]}); } else if(_xml.card.face[i]=="event") { cardArray.push({id:_xml.card.id[i],face:_xml.card.face[i],category:_xml.card.category[i],point:_xml.card.point[i],value:_xml.card.value[i]}); } else { trace("no card found"); } } return cardArray; } public function buildDeck(e:Event):void { for(var i=0;i&lt;cardArray.length;i++) { if(cardArray[i].face == "activity") { activity = new Activity(); activity.x = 200; activity.y = 150; activity.id = i; activity.name = "b"+i; activity.buttonMode = true; stage.addChild(activity); activity.addEventListener(MouseEvent.MOUSE_DOWN,dragStart); activity.addEventListener(MouseEvent.MOUSE_UP,dragStop); } } } public function dragStart(e:Event):void { activity.parent.setChildIndex(activity, numChildren - 1); activity.startDrag(); } public function dragStop(e:Event):void { this.stopDrag(); } } } </code></pre> <p>card.xml</p> <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt; &lt;cardgame&gt; &lt;card&gt; &lt;id&gt;1&lt;/id&gt; &lt;face&gt;activity&lt;/face&gt; &lt;catagory&gt;Task&lt;/catagory&gt; &lt;point&gt;2&lt;/point&gt; &lt;value&gt;Change the rule.&lt;/value&gt; &lt;/card&gt; &lt;card&gt; &lt;id&gt;21&lt;/id&gt; &lt;face&gt;event&lt;/face&gt; &lt;catagory&gt;Injury&lt;/catagory&gt; &lt;point&gt;-2&lt;/point&gt; &lt;value&gt;Injury due to animal/snake/insect bite-count 3.&lt;/value&gt; &lt;/card&gt; &lt;/cardgame&gt; </code></pre> <p>The xml file actually has 64 activity card entries and 41 event card entries, but I trimmed it down to make it easier.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload