'전체 글'에 해당되는 글 1803건

  1. 2011.02.25 JQuery and SWFObject Error
  2. 2011.02.25 ScrapEvent
  3. 2011.02.24 ProportionalScale
  4. 2011.02.22 draw custom round rect border
  5. 2011.02.22 What is an ArrayCollection?
  6. 2011.02.02 MovieClip의 center point 와 Scale변경

JQuery and SWFObject Error

Adobe Flash/Error Note 2011. 2. 25. 01:49
반응형
JQuery and SWFObject Error

version check!!!

ExternalInterface에러 날경우 반드시 확인해볼것.
반응형
:

ScrapEvent

카테고리 없음 2011. 2. 25. 01:46
반응형

  private function scrapBtnDown(e:MouseEvent):void
  {
   //스크랩
   
   var swfLoader:SWFLoader = new SWFLoader();
   var url:String;
   
   if (GlobalConf.swfPath == null) {
    url = "popup.swf"
   }else {
    url = GlobalConf.swfPath + "popup.swf";
   }
   
   GlobalConf.scrapUrl = url;
   
   trace("scrapUrl: " , GlobalConf.scrapUrl);
   
   
   swfLoader.load(url);
   swfLoader.addEventListener(Event.COMPLETE, loaded);
   
   
   var _url:String = GlobalConf.swfPath + "player.swf";
   var _flv:String = GlobalConf.flvPath;
   
   var copyTag:String;
   copyTag = _url + "?flvPath=" + _flv + "tvcf.flv";
 
   ClipboardCopyTag.flvCopyTag(copyTag, "object", 277, 196.5);
   
  }


package com.smilejsu.media
{
 import com.k2.core.GlobalConf;
 import flash.display.MovieClip;
 import flash.display.Sprite;
 import flash.display.StageAlign;
 import flash.display.StageScaleMode;
 import flash.events.Event;
 import flash.events.MouseEvent;
 import flash.external.ExternalInterface;
 
 /*
  *
  * com.smilejsu.media.ScrapPlayer
  *
  */
 public class ScrapPlayer extends MovieClip
 {
  public var player:BasePlayer;
  private var _flvPath:String;
 
  public function ScrapPlayer()
  {
   addEventListener(Event.ADDED_TO_STAGE, init);
  }
 
  private function init(e:Event):void
  {
   removeEventListener(Event.ADDED_TO_STAGE, init);
   
   //스테이지 셋팅
   stage.align = StageAlign.TOP_LEFT;
   stage.scaleMode = StageScaleMode.NO_SCALE;
   stage.showDefaultContextMenu = false;
   
   
   var obj:Object = root.loaderInfo.parameters;
   
   _flvPath =  obj.flvPath;
   
   if (_flvPath == "" || _flvPath == null )
   {
    _flvPath = "";
   }
   
   player.init(_flvPath);
   
   
  }
 }
}



package com.smilejsu.desktop
{
 import flash.display.MovieClip;
 import flash.desktop.Clipboard;
 import flash.desktop.ClipboardFormats;
 
 
 public class ClipboardCopyTag extends MovieClip
 {
  public static const URL:String = "url"
  public static const EMBED:String = "embed"
  public static const OBJECT:String = "object"
 
  public function ClipboardCopyTag()
  {
  }
  public static function flvCopyTag(swfURL:String ,scrapType:String="object", w:Number =680 , h:Number=478):void
  {
   
   var _w:Number = w;
   var _h:Number = h;
   var _scrapType:String = scrapType;
   var _swfURL:String = swfURL;
   var copyUrl:String;
   
   if (_scrapType == ClipboardCopyTag.EMBED) {
   
    copyUrl = '<embed src="' + _swfURL + '" type="application/x-shockwave-flash" allowFullScreen="true" wmode="transparent" width="' + _w + '" height="' + _h + '"></embed>';
   
   }else if (_scrapType == ClipboardCopyTag.OBJECT) {
   
    copyUrl = '<object style="height:' + _h +'px; width:' + _w + 'px"><param name="movie" value="' + _swfURL + '"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="' + _swfURL + '" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="' + _w + '" height="' + _h +'"></object>';
   }
   
   Clipboard.generalClipboard.clear();
   Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, copyUrl);
  }
 
  public static function urlCopyTag(_url:String):void {
   
   Clipboard.generalClipboard.clear();
   Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, _url);
  }
 
  public static function flvTagReturn(swfURL:String ,scrapType:String="object", w:Number =640 , h:Number=360):String {
   var _w:Number = w;
   var _h:Number = h;
   var _scrapType:String = scrapType;
   var _swfURL:String = swfURL;
   var copyUrl:String;
   
   if (_scrapType == ClipboardCopyTag.EMBED) {
   
    copyUrl = '<embed src="' + _swfURL + '" type="application/x-shockwave-flash" allowFullScreen="true" wmode="transparent" width="' + _w + '" height="' + _h + '"></embed>';
   
   }else if (_scrapType == ClipboardCopyTag.OBJECT) {
   
    copyUrl = '<object style="height:' + _h +'px; width:' + _w + 'px"><param name="movie" value="' + _swfURL + '"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="' + _swfURL + '" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="' + _w + '" height="' + _h +'"></object>';
   }
   
   return copyUrl;
  }
 
 }

}

반응형
:

ProportionalScale

Adobe Flash/ActionScript 3.0 2011. 2. 24. 23:37
반응형
  private function ProportionalScale():void
  {
   var $sw:Number    = stage.stageWidth;
   var $sh:Number    = stage.stageHeight;
   var $scale:Number = 0;
  
   if (($sh / $sw) > (video.height / video.width))
   {
    $scale = video.width / video.height;
    video.height = $sh;
    video.width = $sh * $scale;
   } else {
    $scale =video.height / video.width;
      video.width =  $sw;
      video.height = $sw * $scale;
   }
   video.x = ($sw - video.width) / 2;
   video.y = ($sh - video.height) / 2;
  }
반응형

'Adobe Flash > ActionScript 3.0' 카테고리의 다른 글

SWC + FDT4 = SWF  (0) 2011.03.10
FlashDevelop + Molehill + Away3d_4.0.0  (0) 2011.03.10
draw custom round rect border  (0) 2011.02.22
What is an ArrayCollection?  (0) 2011.02.22
MovieClip의 center point 와 Scale변경  (0) 2011.02.02
:

draw custom round rect border

Adobe Flash/ActionScript 3.0 2011. 2. 22. 15:56
반응형

package 
{
 import flash.display.Graphics;
 import flash.display.Shape;
 import flash.display.Sprite;
 
 /**
  * ...
  * @author jang sang wook ( smilejsu@nate.com )
  */
 public class ImagePanel extends Sprite
 {
  private var _g:Graphics;
  
  private var _border:Shape = new Shape;
  
  public function ImagePanel($width:Number, $height:Number, $color:uint, e)
  {
   
   _g = this.graphics;
   _g.beginFill(0xffffff);
   _g.drawRoundRect(0, 0, 300, 200, 5, 5);
   _g.endFill();
   
   _border.graphics.lineStyle(2, Math.random() * 0xffffff);
   _border.graphics.drawRoundRect(0, 0, 300, 200, 5, 5);
   this.addChild(_border);
   
  }
  
 }

}

 

반응형

'Adobe Flash > ActionScript 3.0' 카테고리의 다른 글

FlashDevelop + Molehill + Away3d_4.0.0  (0) 2011.03.10
ProportionalScale  (0) 2011.02.24
What is an ArrayCollection?  (0) 2011.02.22
MovieClip의 center point 와 Scale변경  (0) 2011.02.02
tabIndex  (0) 2011.01.17
:

What is an ArrayCollection?

Adobe Flash/ActionScript 3.0 2011. 2. 22. 09:31
반응형
원문: http://jodieorourke.com/view.php?id=104&blog=news

What is an ArrayCollection?

Posted: 06/04/09

An image of What is an ArrayCollection?

What is an ArrayCollection?

For developers new to Flex, possibly one of the most confusing parts of understanding how to use the Flex Framework is the use of Collections. Collections underpin a lot of the core data display controls in Flex (namely DataProviders), and understanding how they work not only allows effective use of these controls, but also gives the developer a more robust way of handling data throughout their application.

An ArrayCollection is essentially an Array, with a wrapper around it that provides the developer with an enhanced interface to add, remove and sort data. The wrapper also allows notification of changes to the data inside ArrayCollection to be send to registered listening objects as events. If you imagine an ArrayCollection as an Array wearing the kind of robot suit Robert Downey Jnr wore in Ironman, you should get on fine... It does a few extra impressive things, but ultimately there’s an Array inside.

ArrayCollection extends ListCollectionView, which is an implementation of ICollectionView - a view onto a collection of data.

Declaring an ArrayCollection:

An ArrayCollection can be declared in a Flex application in two main ways. With an MXML document it is possible to declare your ArrayCollection with MXML mark-up, or with ActionScript in your script block. In an ActionScript class, it is only possible to declare your ArrayCollection using ActionScript.

With MXML:

<mx:ArrayCollection id="myAC">

<mx:Array>

<mx:Object name="Jodie" country="UK" language="English"/>

<mx:Object name="Kate" country="USA" language="English"/>

<mx:Object name="David" country="France" language="French"/>

</mx:Array>

</mx:ArrayCollection>

The exact same declared with ActionScript:

import mx.collections.ArrayCollection;

private var myAC:ArrayCollection = new ArrayCollection( [ { name: "Jodie", country: "UK", language: "English" }, { name: "Kate", country: "USA", language: "English" }, { name: "David", country: "France", language: "French" } ] );

It is also possible to declare and instantiate your ArrayCollection, and then assign an Array to it, or switch between Arrays at runtime using the source property:

var myArray:Array = [ { name: "Jodie", country: "UK", language: "English" }, { name: "Kate", country: "USA", language: "English" }, { name: "David", country: "France", language: "French" } ];

MyAC.source = myArray;

Adding and removing items from the ArrayCollection

The enhanced interface that the ArrayCollection provides allows you to easily add and remove objects from the underlying Array, including adding and removing objects at a specific index

myAC.addItem( { name: "Lee", country: "China", language: "Mandarin" } );

myAC.removeItemAt( 0 );

myAC.addItemAt( { name: "Jodie", country: "UK", language: "English" }, 0 );

The first line adds an item to the end of the underlying Array. The second line removes the first item in the underlying Array; causing all of the remaining items to move down one position. Finally, the third line adds a new item to the first position in the Array; causing all of the other items to move up one position.

Sorting an ArrayCollection

The data in the ArrayCollection is now very mixed-up, with little or no order to it, since we’ve added and removed some items.

Being able to sort data in the ArrayCollection with relative ease is something that is provided with the combined use of Sort() and SortField() objects.

var mySort:Sort = new Sort();

mySort.fields = [ new SortField( "country", true ) ];

myAC.sort = mySort;

myAC.refresh();

trace( myAC );

The important thing to always remember (but you’ll forget at least once) is to ensure you call the refresh() method on the ArrayCollection after applying the sort. Failing to do so will not update the ArrayCollection.

The handy thing about specifying your sort fields as an Array it that you can add more, offering a first, second, third (or more) order of sorting. In this example, the resulting ArrayCollection will be sorted by country first, followed then by name, and then by language:

var mySort:Sort = new Sort();

mySort.fields = [ new SortField( "country", true ), new SortField( "name", true ), new SortField( "language", true ) ];

myAC.sort = mySort;

myAC.refresh();

Receiving notifications when things change

Probably the most useful aspect of an ArrayCollection over an Array is its ability to notify when changes have been made to it. Because objects like ArrayCollection dispatch the CollectionEvent.COLLECTION_CHANGE event, they’re not only able to be used with the manual event dispatch and listening procedures that most Flash Developers are familiar with, but they also plug-in to the Binding capabilities of the Flex Framework. This means that through the use of very simple meta-data and curly-brace notation {}, the listening and handling of events can be handled entirely by the Binding (more about Data Binding in Flex). As a developer, this means that you can remove some of the hassle of understanding when you need to update a display object with updated data.

In the first example, here’s how manual notification of changes to the data in the underlying Array of an ArrayCollection works:

myAC.addEventListener( CollectionEvent.COLLECTION_CHANGE, onChange );

private function onChange( e:CollectionEvent ) :void

{

trace( 'collection changed' );

}

Note that sorting an ArrayCollection will dispatch the COLLECTION_CHANGE event as well as when you add and remove items; this is because a sort changes the position of items in the underlying Array.

Manually assigning listeners and responding to changes in the ArrayCollection is something you’ll seldom do when building Flex applications, this is because Bindings generally handle most of this for you. In the next example, a DataGrid is updated each time the ArrayCollection changes. The ArrayCollection is defined using MXML mark-up. Feel free to paste this code into your IDE and run it.

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

<mx:Script>

<![CDATA[

import mx.events.CollectionEvent;

import mx.collections.SortField;

import mx.collections.Sort;

private function onClick( e:MouseEvent ) :void

{

myAC.addItem( { name: "Lee", country: "China", language: "Mandarin" } );

myAC.removeItemAt( 0 );

myAC.addItemAt( { name: "Jodie", country: "UK", language: "English" }, 0 );

sortCollection();

}

private function sortCollection() : void

{

var mySort:Sort = new Sort();

mySort.fields = [ new SortField( "country", true ), new SortField( "name", true ), new SortField( "language", true ) ];

myAC.sort = mySort;

myAC.refresh();

}

]]>

</mx:Script>

<mx:ArrayCollection id="myAC">

<mx:Array>

<mx:Object name="Jodie" country="UK" language="English"/>

<mx:Object name="Kate" country="USA" language="English"/>

<mx:Object name="David" country="France" language="French"/>

</mx:Array>

</mx:ArrayCollection>

<mx:DataGrid id="myDG" dataProvider="{myAC}"/>

<mx:Button id="myButton" label="Update" click="onClick(event)"/>

</mx:Application>

As you’ll see, clicking the button labelled “Update” causes the ArrayCollection have an item removed, and two items added, and finally a sort applied to it. By specifying the dataProvder property of the DataGrid as ‘bound’ to the ArrayCollection instance, through the use of curly-braces {}, the binding capabilities of the Flex Framework take over when the ArrayCollection changes, and automatically notify the DataGrid to update.

Searching an ArrayCollection for a value

Another important thing to be able to is search your ArrayCollection for occurrences of a particular value. This can be done with the use of a Cursor object, that acts like a marker on your ArrayCollection, highlighting where a match is found. The key thing to remember with a Cursor is that it needs to be used in conjunction with a Sort; if you haven’t yet applied a sort to the ArrayCollection, the Cursor isn’t going to work.

In the code below, I apply a Sort to the ArrayCollection when the application has completed rendering. The user is then able to enter a search term into TextInput field, and when they click on the search button, a cursor is created that performs a look-up along the “name” values in the objects on the underlying Array for instances of the value entered. If one is found, the Cursor position is updated, and the resulting event callback updates another ArrayCollection that is bound to a DataGrid; showing the result that was found.

Again, copy the code into your IDE and run it, if you like.

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" creationComplete="init(event)">

<mx:Script>

<![CDATA[

import mx.events.FlexEvent;

import mx.collections.IViewCursor;

import mx.events.CollectionEvent;

import mx.collections.SortField;

import mx.collections.Sort;

import mx.collections.ArrayCollection;

private function init( e:Event ) :void

{

var mySort:Sort = new Sort();

mySort.fields = [ new SortField( "name", true ), new SortField( "language", true ), new SortField( "country", true ) ];

myAC.sort = mySort;

myAC.refresh();

}

private function onSearchClick( e:MouseEvent ) :void

{

var cursor:IViewCursor = myAC.createCursor();

cursor.addEventListener( FlexEvent.CURSOR_UPDATE, onCursorUpdate );

cursor.findAny( { name:null,language:null,country:searchText.text } );

}

private function onCursorUpdate( e:FlexEvent ) :void

{

myCursorResult.source = [ {name: e.target.current.name, country:e.target.current.country} ];

}

]]>

</mx:Script>

<mx:ArrayCollection id="myAC">

<mx:Array>

<mx:Object name="Jodie" country="UK" language="English"/>

<mx:Object name="Kate" country="USA" language="English"/>

<mx:Object name="David" country="France" language="French"/>

</mx:Array>

</mx:ArrayCollection>

<mx:ArrayCollection id="myCursorResult"/>

<mx:TextInput id="searchText"/>

<mx:Button label="Search" click="onSearchClick(event)"/>

<mx:DataGrid dataProvider="{myCursorResult}"/>

</mx:Application>

You also need to bear in mind that the search properties specified in the object you supply to the Cursor’s findAny(), findFirst() or findLast() methods need to be in the same order that they are specified in the Sort. For example, in the above code, my “name” SortField comes first, so I can specify the name field in the Cursor. If, however, I wanted to search for “country”, I would need to specify “name”, “language” and the “country” in my Cursor, as this is the order by which they are specified in the sort.

You see that by changing the sort applied to the ArrayCollection, so that only the “country” sort field is specified, I don’t need to provide the other field values to the Cursor, and the search will only include matching “country” objects.

private function onSearchClick( e:MouseEvent ) :void

{

var mySort:Sort = new Sort();

mySort.fields = [ new SortField( "country", true ) ];

myAC.sort = mySort;

myAC.refresh();

var cursor:IViewCursor = myAC.createCursor();

cursor.addEventListener( FlexEvent.CURSOR_UPDATE, onCursorUpdate );

cursor.findAny( { country:searchText.text } );

}

So there you have it; more than a seemingly useless object that Adobe insists you convert your objects to so as to be able to use the List components! It does plenty more than I’ve shown here, and hopefully I’ll be able to follow this post up with some more interesting uses of ArrayCollection – provided this post is well received! Remember also that there’s XMLListCollection, which brings E4X to the party too...

Further reading:

Implementing the Presentation Model in Flex using daisy-chained ArrayCollections

반응형

'Adobe Flash > ActionScript 3.0' 카테고리의 다른 글

FlashDevelop + Molehill + Away3d_4.0.0  (0) 2011.03.10
ProportionalScale  (0) 2011.02.24
draw custom round rect border  (0) 2011.02.22
MovieClip의 center point 와 Scale변경  (0) 2011.02.02
tabIndex  (0) 2011.01.17
:

MovieClip의 center point 와 Scale변경

Adobe Flash/ActionScript 3.0 2011. 2. 2. 03:32
반응형
http://www.senocular.com/flash/tutorials/transformmatrix/

Transformation Conversions

Sometimes you may need to compare transformation matrix values with those that exist in the Flash IDE or to those used in more generic ActionScript properties. Transformation matrix values, however, do not always correlate with their other Flash counterparts. Translation, for instance, relates directly to those values expressed as x (_x) and y (_y) position in Flash, but scale, skew, and rotation are handled slightly differently.

translation

Translation is, for the most part, the easy one. The tx and ty properties in a matrix directly relate to the _x and _y properties provided by ActionScript to reflect a movie clip's position within it's parent timeline. The values present in the Flash IDE in the property inspector, however, can differ.

The Flash IDE allows for position to be based on two separate locations. That of the top left of the movie clip or that of the movie clip's center. The option of using either is presented in the coordinate grid of the info panel

This center option does not always represent the local 0,0 location, or origin, of the movie clip in question, though. It's actually related to the transformation center point provided by the transform tool and is represented as a small black and white circle in Flash. By default this is placed in the center of a movie clip instance but can be adjusted using the transform tool. In order for translation values, or even _x and _y for that matter, to match up with this transformation center point, it would need to be placed on the origin of the movie clip which is represented by a black and white cross.

The transformation center point is not accessible by ActionScript, so keep that in mind as you are working with movie clips in Flash. It is often best to keep the registration point aligned with the movie clip's origin so you have a direct relation with the values you see in the Flash IDE and those accessible through ActionScript.

var my_matrix = my_mc.transform.matrix;

trace("x: " + my_matrix.tx);
trace("y: " + my_matrix.ty);

scale

Scale mostly relates directly to the a and d properties of a transformation matrix but is complicated by the effects of skewing. Without skewing, the a and b properties directly relate to the scale properties presented by flash - those in the IDE's transform panel and those given by _xscale and _yscale in ActionScript - with the simple exception of a matrix's scale being based on 1 while Flash bases scale on 100 for a scale of 100%.

When skewing is involved, the scale of an axis changes as it continues to stretch based on the relationship to the other axis, either x to y or vice versa. Because of these relations, its only a matter of using Pythagoreans theorem to acquire the correct scale factor

var my_matrix = my_mc.transform.matrix;

trace("x scale: " + Math.sqrt(my_matrix.a * my_matrix.a + my_matrix.b * my_matrix.b));
trace("y scale: " + Math.sqrt(my_matrix.c * my_matrix.c + my_matrix.d * my_matrix.d));

skew

Prior to transformation matrices in Flash 8, skew values were not accessible through ActionScript. The Flash IDE, however, did, and still does, provide values for skew in the transform panel in the form of values of rotation (in degrees). This is slightly different than the values used to interpret this transformation in the actual transform matrix. Values there represent a ratio by which one axis scales according to the other. They are not rotation or angle values.

The rotation values given by Flash represent the angles created on the opposite axis as a result of that axis being skewed. For example, skewing the x axis creates an angle between the now tilted y axis and its original vertical orientation.

Depending on the amount of skew, this angle varies. Using an arbitrary point along either axis and transforming it with a movie clip's matrix will allow us to obtain the value of this rotation using arctangent. An additional 90 degree offset is needed with x skew compensate for the orientation of the y axis.

var my_matrix = my_mc.transform.matrix;

var px = new flash.geom.Point(0, 1);
px = my_matrix.deltaTransformPoint(px);
var py = new flash.geom.Point(1, 0);
py = my_matrix.deltaTransformPoint(py);

trace("x skew: " +((180/Math.PI) * Math.atan2(px.y, px.x) - 90));
trace("y skew: " +((180/Math.PI) * Math.atan2(py.y, py.x)));

rotation

If you know skew, you know rotation. Flash uses the x skew angle for rotation.

var my_matrix = my_mc.transform.matrix;

var px = new flash.geom.Point(0, 1);
px = my_matrix.deltaTransformPoint(px);

trace("rotation: " +((180/Math.PI) * Math.atan2(px.y, px.x) - 90));

반응형

'Adobe Flash > ActionScript 3.0' 카테고리의 다른 글

FlashDevelop + Molehill + Away3d_4.0.0  (0) 2011.03.10
ProportionalScale  (0) 2011.02.24
draw custom round rect border  (0) 2011.02.22
What is an ArrayCollection?  (0) 2011.02.22
tabIndex  (0) 2011.01.17
: