cuboctahedron
01-04-2007, 09:42 AM
Hi,
Currently I have all my components in a level0 movie (swf). Other movies on top (level1 etc.) can use the components from level0, so that the filesize of the swf file will be small. This seems to work fine.
Currently I am building a movieclip on level1, and am experimenting with actionscript:
The code (which I took from a tutorial) says
import mx.core.UIComponent
import mx.controls.ComboBox
import mx.controls.DataGrid
Apparently it is including the complete components in the level1 movieclip, while I want it to refer to my level0 components.
I've tried things like _level0.import mx.core.UIComponent but that didnt help.
I've truly looked everywhere on the web for this; surely there must be a solution?
Is it perhaps a linkage issue? I assume if you can link components, you can import from another level too?
How can I modify this actionscript so it will import from a level0 movie?
thanks for your help
Patrick
cuboctahedron
01-05-2007, 02:02 PM
Anyone please able to help me out?
Is it not possible in Flash?
Slowburn
01-05-2007, 05:32 PM
I'm not quite sure what your asking here.
are you looking to load Classes at runtime, then have other MovieClips access/use those Classes?
cuboctahedron
01-05-2007, 10:00 PM
Hi,
ok, this is my situation,
in 'level0.swf' I've added loads of components (e.g. a datagrid) to the stage, so they appear in my library. For example the datagrid has linkage properties set like:
- export for actionscript
- export for runtime sharing
- export in first frame
- URL 'level0.swf'
This way other swf-files can use the datagrid and other components from 'level0.swf', thus keeping swf-sizes to a minimum. This is achieved in the linkage 'import for runtime sharing'.
This works all well so far, as I am able to use the components.
Currently I am trying to understand a tutorial whereby I can add a checkbox to the datagrid.
The script wants to 'import' components using actionscript, but in doing so, places the component in the current movie, as opposed of using the linkage of the component in level0.swf, thereby dramatically increasing the swf file-size.
for example, an AS-include file has the following code:
import mx.core.UIComponent
import mx.controls.CheckBox
class CheckBoxCell extends UIComponent
{
private var check : MovieClip;
private var listOwner : MovieClip;
private var getCellIndex : Function;
private var getDataLabel : Function;
private static var PREFERRED_HEIGHT = 16;
private static var PREFERRED_WIDTH = 20;
// Constructor: Should be empty.
public function CheckBoxCell()
{
}
public function createChildren(Void) : Void
{
check = createObject("CheckBox", "check", 1, {styleName:this, owner:this});
check.addEventListener("click", this);
size();
}
public function size(Void) : Void
{
check.setSize(PREFERRED_WIDTH, PREFERRED_WIDTH);
check._x = (__width - PREFERRED_WIDTH)/2;
check._y = (__height - PREFERRED_HEIGHT)/2;
}
public function setValue(str:String, item:Object, sel:Boolean) : Void
{
check._visible = (item!=undefined);
check.selected = item[getDataLabel()];
}
public function getPreferredHeight(Void) : Number
{
return PREFERRED_HEIGHT;
}
public function getPreferredWidth(Void) : Number
{
return PREFERRED_WIDTH;
}
public function click()
{
listOwner.dataProvider.editField(getCellIndex().it emIndex, getDataLabel(), check.selected);
}
}
If I remove the lines below, I was hoping the script would use the datagrid component from my 'level0.swf'
import mx.core.UIComponent
import mx.controls.CheckBox
If I do so, I get a parse error saying:
**Error** E:\xampp\xampp\htdocs\website\temp\CheckBoxCell.as : Line 5: The class or interface 'UIComponent' could not be loaded.
Trying 'import _level0.mx.core.UIComponent' didnt work neither.
By the way, to code in frame1 is:
// Build data provider for the data grid with three columns of data.
myDP = new Array();
myDP.addItem({desc:"article1", yes:true, perhaps:false, list1:1, list2:2});
myDP.addItem({desc:"article2", yes:false, perhaps:true, list1:2, list2:1});
myDP.addItem({desc:"article3", yes:false, perhaps:true, list1:0, list2:1});
myDP.addItem({desc:"article4", yes:true, perhaps:false, list1:1, list2:2});
// Assign data provider to the grid to populate it.
// Note: This has to be done before applying the cellRenderers.
grid.dataProvider = myDP;
// Set some basic grid properties.
grid.getColumnAt(0).width = 100;
grid.getColumnAt(1).width = 100;
grid.getColumnAt(2).width = 100;
grid.getColumnAt(3).width = 150;
grid.getColumnAt(4).width = 150;
grid.resizableColumns = true;
grid.vScrollPolicy = "auto";
// Assign cell renderer classes to specific columns.
grid.getColumnAt(1).cellRenderer = "CheckBoxCell";
grid.getColumnAt(2).cellRenderer = "CheckBoxCell";
grid.getColumnAt(3).cellRenderer = "ComboBoxCell";
grid.getColumnAt(4).cellRenderer = "ComboBoxCell";
/* CellPress handler
Outputs information on the row containing the cell that
broadcast the CellPress event. */
this.cellPress = function( evt_obj:Object )
{
status.text="";
if(evt_obj.itemIndex != undefined)
{
status.text += "Cell pressed in row: " + evt_obj.itemIndex + "\r";
}
if(grid.selectedItem.yes != undefined)
{
status.text += "Row has been selected. Row data: \r";
status.text += "\t\t" + "desc: " + grid.selectedItem.desc + "\r";
status.text += "\t\t" + "yes: " + grid.selectedItem.yes + "\r";
status.text += "\t\t" + "perhaps: " + grid.selectedItem.perhaps + "\r";
status.text += "\t\t" + "list1: " + grid.selectedItem.list1 + "\r";
}
if(grid.selectedItem.selectVal != undefined)
{
status.text += "select Val: " + grid.selectedItem.OptionVal + "\r";
grid.dataProvider.editField(getCellIndex().itemInd ex, getDataLabel(), check.selected);
}
if(grid.selectedItem.OptionVal != undefined)
{
status.text += "ComboBox Data Val: " + grid.selectedItem.OptionVal + "\r";
}
}
// Add a listener for the the grid cellPress event.
grid.addEventListener("cellPress", this);
Hope that explains my situation better.
Flash Gordon
01-05-2007, 10:10 PM
i think you are looking for an _exclude.xml file...see the attached file for an example.
cuboctahedron
01-06-2007, 10:16 PM
Hi,
Thanks for the help so far! I've looked at the file, but I don't quite understand how to apply it for components.
How would you have to use it in the example of my last post?
cheers
Patrick
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.