topical media & game development
student-editor-net-ximpel-components-SubjectView.mx
student-editor-net-ximpel-components-SubjectView.mx
[swf]
flex
<?xml version="1.0" encoding="utf-8"?>
<!--
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Javier Quevedo Fernández 05-2009.
-->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:fc="http://www.adobe.com/2006/fc"
width="99%" height="98%"
styleName="SubjectView"
xmlns:xim="net.ximpel.components.*"
horizontalCenter="0"
creationComplete="init()"
dragDrop="dragDropHandler(event);"
dragEnter="dragEnterHandler(event);"
click="clickHandler(event);">
<mx:Script>
<![CDATA[
import com.adobe.flex.extras.controls.springgraph.IViewFactory;
import mx.controls.Image;
import mx.controls.ComboBox;
import mx.events.DragEvent;
import net.ximpel.classes.*
import mx.managers.DragManager;
import com.adobe.flex.extras.controls.springgraph.SpringGraph;
import com.adobe.flex.extras.controls.springgraph.Item;
import com.adobe.flex.extras.controls.springgraph.Graph;
import net.ximpel.events.InterfaceEvents;
[bindable]
public var subject:Subject = new Subject();
[bindable]
public var currentMedia:Object;
public var clipCount:int=0;
private var _previousItem:XimpelGraphItem;
private var _graph : Graph = new Graph();
private var firstRun : Boolean = true;
public function init():void
{
var itemRenderer:ClassFactory = new ClassFactory(MediaClipView);
springGraph.itemRenderer=itemRenderer;
}
public function addMedia(type:String, imgSource : String):void {
if (firstRun){
helpCanvas.parent.removeChild(helpCanvas);
firstRun = false;
}
var item:XimpelGraphItem = new XimpelGraphItem(new Number(clipCount).toString(),new Number(clipCount).toString(),type, imgSource);
item.id = clipCount.toString();
item.addEventListener(InterfaceEvents.MEDIA_CLIP_REMOVED, removeVideo);
_graph.add(item);
if(_previousItem != null)
_graph.link(item, _previousItem);
_previousItem = item;
springGraph.dataProvider = _graph;
clipCount++;
}
public function addVideo():void {
}
public function updateInfo():void{
var parentCanvas : Canvas = this.parent as Canvas;
parentCanvas.label = subject.id;
}
public function mediaselected(media : Object):void {
if (currentMedia && currentMedia != media){
var _mediaClipView : MediaClipView = currentMedia as MediaClipView;
_mediaClipView.setAsNotSelected();
}
this.currentMedia = media;
dispatchEvent(new InterfaceEvents("mediaActivated"));
}
private function findNextElementInGraph(id : String):String{
var nodes : Object = _graph.nodes;
var graphItem : XimpelGraphItem;
for (var node : Object in nodes) {
graphItem = node as XimpelGraphItem;
if (parseInt(id) > parseInt(graphItem.graphId))
return (graphItem.graphId);
}
return null;
}
public function notifyClipAdded(clipView : MediaClipView) : void {
this.subject.addClip(clipView.clip);
}
public function removeVideo(clipView : MediaClipView):void {
var item : XimpelGraphItem = _graph.find(clipView.itemId) as XimpelGraphItem;
var nodes : Object = _graph.nodes;
var neighbors : Array = new Array();;
for (var key:Object in _graph.neighbors(clipView.itemId)){
var keyString : String = key as String;
neighbors.push(nodes[key]);
}
var _previousNode : XimpelGraphItem;
var _nextNode : XimpelGraphItem;
var numlinks : int = _graph.numLinks(item);
this.subject.removeClip(clipView.clip);
_graph.remove(item);
if (neighbors[0])
_previousNode = neighbors[0] as XimpelGraphItem;
if (neighbors[1])
_nextNode = neighbors[1] as XimpelGraphItem;
// Only one clip
if (!neighbors[0] && !neighbors[1]){
_previousItem = null;
clipCount = 0;
return;
}
// First clip
if (neighbors[0] && !neighbors[1] && item != _previousItem){
return;
}
// Last clip
if (neighbors[0] && item == _previousItem){
_previousItem = neighbors[0];
clipCount--;
return;
}
// Rest of the clips
_graph.link(neighbors[0], neighbors[1]);
}
private function dragDropHandler(event:DragEvent):void {
addMedia(event.dragSource.formats[0], event.dragSource.formats[1]);
}
private function dragEnterHandler(event:DragEvent):void {
DragManager.acceptDragDrop(Canvas(event.currentTarget));
}
private function clickHandler (event:MouseEvent):void {
dispatchEvent(new InterfaceEvents("subjectActivated"));
}
private function subjectFormMouseDownHandler (event : InterfaceEvents):void
{
var comboBox : ComboBox = event.currentTarget as ComboBox;
}
private function subjectFormChangedHandler (event : InterfaceEvents):void
{
//updateSubject();
}
]]>
</mx:Script>
<mx:Canvas width="100%" height="100%">
<fc:SpringGraph id="springGraph" backgroundColor="#DDDDDD"
lineColor="#6666ff" repulsionFactor="{slider.value*1.2}" width="100%" height="100%">
<mx:Canvas id="helpCanvas" styleName="HelpCanvas" horizontalCenter="0"
verticalCenter="0"
width="200"
height="200">
<mx:TextArea width="100%"
height="100%"
backgroundAlpha="0"
borderThickness="0"
selectable="false"
editable="false">
<mx:htmlText><![CDATA[
To add a clip please drag and drop a media element from the Media Tools Panel.]]>
</mx:htmlText>
</mx:TextArea>
</mx:Canvas>
</fc:SpringGraph>
<mx:Label text="Distance" top="7" right="140"/>
<mx:HSlider width="120" id="slider" top="4" right="10" value="0.5" minimum="0.01" maximum="1.0"/>
</mx:Canvas>
</mx:Canvas>
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.