View Full Version : passing var to embedded swf resource
I'm trying to import an swf and, at load time, pass a var through query parameter .. like this .. into a txt field ..
<view x="50" y="200" oninit="this.setSource('http:test.swf?txt=Hello')"/>
but txt parameter is not passed .. any ideas?
...
The more general question is .. how to target objects/vars in embedded swf resources, to/from host openlaszlo app?
jstretch
03-13-2006, 07:02 AM
I think I've tried about 10 different approaches with no luck. I keep coming back to the debugger. Here is when I debug the view 'test' and then MediaLoader. I going to investigate the medialoader futher, or any other possible links to the resource.
<view id="test" width="200" height="50" oninit="${this.setSource('resources/test.swf')}" />
#test {
_events: [LzEvent]
_instanceAttrs: «Object#1#3| {id: test, height: 50, width: 200}»
_instanceChildren: «undefined»
addedToParent: true
checkPlayStatusDel: #test.checkPlayStatus2()
currentframe: 1
doQueuedDel: #test.doQueuedPlayAction()
errorDel: #test.__LZsendError()
firstcache: «undefined»
firstheaders: «undefined»
firstsrc: resources/test.swf
frame: 1
framesloadratio: 1
hassetheight: true
hassetwidth: true
height: 50
id: test
immediateparent: «LzCanvas#7| This is the canvas»
isinited: true
isloaded: true
loader: «LzMediaLoader#9| «MediaLoadObj#8| test.swf (loaded)»»
loadperc: 1
loadratio: 1
mask: null
nodeLevel: 1
oninit: «undefined»
onload: #test.onload
parent: «LzCanvas#7| This is the canvas»
playing: false
queuedplayaction: null
resource: resources/test.swf
resourceheight: 24.65
resourcewidth: 183
timeoutDel: #test.__LZsendTimeout()
totalframes: 1
txt: asdf
updateDel: #test.updateAfterLoad()
visible: true
width: 200
}
«LzView#13#0| #test»
«LzMediaLoader#9| «MediaLoadObj#8| test.swf (loaded)»» {
_events: [LzEvent, LzEvent, LzEvent, LzEvent]
_sCall: LzLoader.unload
checkonce: true
copyTaskDel: «LzDelegate#16| «LzMediaLoader#9| «MediaLoadObj#8| test.s...».copyFl...»
lastloadtime: 0
lastrequest: «MediaLoadObj#8| test.swf (loaded)»
loadChecker: «LzDelegate#17| «LzMediaLoader#9| «MediaLoadObj#8| test.s...».testLo...»
loadmcdepth: 1
loadmclist: []
loadmcnum: 2
mc: «MediaLoadObj#8| test.swf (loaded)»
onerror: «ˇLzEvent!#19| «LzMediaLoader#9| «MediaLoadObj#8| test.s...».onerror»
onloaddone: «ˇLzEvent!#20| «LzMediaLoader#9| «MediaLoadObj#8| test.s...».onloadd...»
onstreamstart: «ˇLzEvent!#21| «LzMediaLoader#9| «MediaLoadObj#8| test.s...».onstrea...»
ontimeout: «ˇLzEvent!#22| «LzMediaLoader#9| «MediaLoadObj#8| test.s...».ontimeo...»
owner: #test
proxied: true
removeLoadCheckerDel: «LzDelegate#23| «LzMediaLoader#9| «MediaLoadObj#8| test.s...».remove...»
sentLoadStart: true
timeout: 30000
}
I got similar results using
Debug.inspect(canvas);
There was reference in an earlier thread (http://www.laszlosystems.com/developers/community/forums/showthread.php?threadid=2989&highlight=resource) to using
Debug.showInternalProperties = true
in debugger window .. but I have not been able to figure out how to apply this to view imported movie attributes ..
we need an internal "DOM inspector" for imported movies.
jstretch
03-13-2006, 07:36 AM
That helped. The debugger can see it, but javascript doesnt.
Debug.write(test.__LZmovieClipRef._level0);
«MovieClip#3| _level0» {
$class: #$class
$debug: true
$instanceof: $instanceof
$krank: false
$m0: «MovieClip#7| _level0.$m0»
$m1: «MediaLoadObj#8| test.swf (loaded)»
$m2: «MovieClip#9| _level0.$m2»
$profile: false
$reportNotFunction: $reportNotFunction
$reportSourceWarning: $reportSourceWarning
$reportUndefinedMethod: $reportUndefinedMethod
$reportUndefinedObjectProperty: $reportUndefinedObjectProperty
$reportUndefinedProperty: $reportUndefinedProperty
$reportUndefinedVariable: $reportUndefinedVariable
$rightclkmenu: «MovieClip#16| _level0.$rightclkmenu»
$runtime: swf6
$swf6: true
$swf7: false
$version: WIN 8,0,22,0
_: «MovieClip#3| _level0»
__: true
___: null
__LzDebug: #Debug
__lzhistconn: 9962
__lzhisturl: /laszlo_cct/lps/includes/h.html?h=
__LzLeaks: __LzLeaks
__LzStackFrame: __LzStackFrame
__proto__: «Object#20| MovieClip.prototype»
_componentmanager: _componentmanager
_Copyright: «string(96)#22| "Portions of this file are copyright (c) 2001-2004 b...»
_currentframe: 1
_dbg_cmd_eval: #_dbg_cmd_eval
_dbg_cmd_hist_next: #_dbg_cmd_hist_next
_dbg_cmd_hist_prev: #_dbg_cmd_hist_prev
_dbg_horiz_scrollbar: _dbg_horiz_scrollbar
_dbg_log_all_writes: false
_dbg_lzhdrag: _dbg_lzhdrag
_dbg_lztextscroller: _dbg_lztextscroller
_dbg_lzvdrag: _dbg_lzvdrag
_finishndi: LzDatapointer.finishRootNode
_m: LzDatapointer.makeElementNode
_opacity: «undefined»
_rootndi: LzDatapointer.makeRootNode
_rotation: 0
_t: LzDatapointer.makeTextNode
_visible: true
_x: 0
_xscale: 100
_y: 0
_yscale: 100
aqua: 65535
basebutton: basebutton
basecomponent: basecomponent
basefocusview: basefocusview
black: 0
blue: 255
canvas: «LzCanvas#37| This is the canvas»
cheesyMultipleInheritance: cheesyMultipleInheritance
Class: Class
constantboundslayout: constantboundslayout
constantlayout: constantlayout
constructor: MovieClip
ConstructorMap: #ConstructorMap
Debug: #Debug
debug: true
debugger_shadow_bottom: debugger_shadow_bottom
debugger_shadow_right: debugger_shadow_right
dhsb: #dhsb
dragstate: dragstate
entercontrol: «MovieClip#48| _level0.entercontrol»
eval: eval
focusoverlay: focusoverlay
frameupdate: «MovieClip#51| _level0.frameupdate»
fuchsia: 16711935
global: «MovieClip#3| _level0»
gold1: 9331721
gold2: 13349195
gold3: 15126388
gold4: 16311446
gray: 8421504
gray10: 1710618
gray20: 3355443
gray30: 5066061
gray40: 6710886
gray50: 8355711
gray60: 10066329
gray70: 11776947
gray80: 13421772
gray90: 15066597
grayblue: 12501704
graygreen: 12635328
graypurple: 10460593
green: 32768
iceblue1: 3298963
iceblue2: 5472718
iceblue3: 12240085
iceblue4: 14017779
iceblue5: 15659509
inspect: inspect
instance1: «Button#53| {}»
lime: 65280
ltblue: 14540287
ltgreen: 14548957
ltpurple1: 6575768
ltpurple2: 12038353
ltpurple3: 13353453
ltpurple4: 15329264
lzAddLocalData: lzAddLocalData
LzAgent: «Function#55| "data/LzConnection.as"#23/15»
LzAnimator: LzAnimator
LzAnimatorGroup: LzAnimatorGroup
LzAudio: #LzAudio
LzBacktrace: LzBacktrace
LzBrowser: #LzBrowser
LzCanvas: LzCanvas
LzCanvasGradient: LzCanvasGradient
LzCommand: LzCommand
LzConnection: LzConnection
LzConnectionDatasource: LzConnectionDatasource
LzCursor: #LzCursor
LzDataAttrBind: LzDataAttrBind
LzDataElement: LzDataElement
LzDataNode: LzDataNode
LzDatapath: LzDatapath
LzDatapointer: LzDatapointer
LzDataSelectionManager: LzDataSelectionManager
LzDataset: LzDataset
LzDatasource: LzDatasource
LzDataText: LzDataText
LzDebugWindow: LzDebugWindow
LzDelegate: LzDelegate
LzDrawView: LzDrawView
LzError: LzError
LzEvent: LzEvent
LzFixTags: LzFixTags
LzFocus: #LzFocus
LzFont: LzFont
LzFontManager: #LzFontManager
LzGlobalMouse: #LzGlobalMouse
LzHistory: #LzHistory
LzHttpDatasetPool: #LzHttpDatasetPool
LzHTTPDatasource: LzHTTPDatasource
LzIdle: #LzIdle
LzInputText: LzInputText
LzInstantiateView: LzInstantiateView
LzInstantiator: #LzInstantiator
LzKeys: #LzKeys
LzLayout: LzLayout
LzLazyReplicationManager: LzLazyReplicationManager
LzLibrary: LzLibrary
LzLibraryCleanup: LzLibraryCleanup
LzLibraryLoader: LzLibraryLoader
LzLoader: LzLoader
LzLoadQueue: #LzLoadQueue
LzMakeClass: LzMakeClass
LzMakeLoad: «LzTransformer#102| {}»
LzMediaLoader: LzMediaLoader
LzMessage: LzMessage
LzModeManager: #LzModeManager
LzMonitor: LzMonitor
LzNode: LzNode
LzNotifyingEvent: LzNotifyingEvent
LzParam: LzParam
LzParsedPath: LzParsedPath
LzReplicationManager: LzReplicationManager
LzResizeReplicationManager: LzResizeReplicationManager
LzScript: LzScript
LzSelectionManager: LzSelectionManager
LzSerializer: «Object#115| LzSerializer»
LzState: LzState
lzt: swf
LzText: LzText
LzTimer: #LzTimer
LzTrace: LzTrace
LzTrack: #LzTrack
LzTransformer: LzTransformer
LzURL: LzURL
LzUserClass: LzUserClass
LzView: LzView
LzViewLinkage: LzViewLinkage
LzWarning: LzWarning
maroon: 8388608
mouseListener: #mouseListener
mvn: «Function#128| "core/LzNode.as"#16/11»
navy: 128
offwhite: 15921906
olive: 8421376
palegreen1: 4290113
palegreen2: 11785139
palegreen3: 12637341
palegreen4: 13888170
palegreen5: 15725032
purple: 8388736
red: 16711680
resizelayout: resizelayout
resizestate: resizestate
reverselayout: reverselayout
sand1: 13944481
sand2: 14276546
sand3: 15920859
sand4: 15986401
silver: 12632256
simpleboundslayout: simpleboundslayout
simplelayout: simplelayout
SoundMC: SoundMC
stableborderlayout: stableborderlayout
statictext: statictext
style: style
TagFunctionMap: #TagFunctionMap
teal: 32896
test: #test
UserClassPlacementObject: UserClassPlacementObject
white: 16777215
wrappinglayout: wrappinglayout
yellow: 16776960
}
«MovieClip#3| _level0»
Now the task is to figure out how to create a setter for this object -OR- to possible have this object access a variable in its host.
edit: added internal properties to debug output
Shelby
03-13-2006, 07:41 AM
I don't know if this will help you at all, but I spent some time a while ago trying to play .FLV files in Laszlo. Basically, I created a movie object called theVideo in my SWF and when I load the swf in Laszlo I access theVideo to attach a NetStream to it. I was also playing around with connecting a web cam, which explains the commented line with the Camera.get().
<canvas debug="true">
<button name="test_button" onclick="captureFrame(myDisplay.mc.theVideo.width, myDisplay.mc.theVideo.height);" text="Capture Frame">
<method args="awidth,aheight" name="captureFrame"><![CDATA[
var snapshot = new flash.display.BitmapData(awidth, aheight, false, 0x00ffff);
var output_vid = myDisplay.mc.theVideo;
snapshot.draw(output_vid, new flash.geom.Matrix());
var frameCapture_mc = frameCapture.getMCRef();
frameCapture_mc.createEmptyMovieClip("bitmap_mc", frameCapture_mc.getNextHighestDepth());
frameCapture_mc.bitmap_mc.attachBitmap(snapshot, 1);
frameCapture_mc.bitmap_mc.x = 10;
/* _root.createEmptyMovieClip("bitmap_mc", _root.getNextHighestDepth());
bitmap_mc.x = 300;
bitmap_mc.y = 50;
bitmap_mc.attachBitmap(snapshot, 1);
Debug.write(bitmap_mc);
*/
]]>
</method>
</button>
<view bgcolor="red" height="200" name="frameCapture" stretches="both" width="200" x="300" y="50">
<method event="oninit">
setSource('goal.swf');
</method>
</view>
<view height="200" name="myDisplay" stretches="both" width="200" x="50" y="50">
<attribute name="nc" value="null"></attribute>
<attribute name="ns" value="null"></attribute>
<attribute name="mc" value="null"></attribute>
<attribute name="intervalID" type="number" value="0"></attribute>
<method event="oninit">
setSource('streamContainer.swf');
</method>
<method args="infoObject" name="onStatus"><![CDATA[
Debug.write("NetStream.onStatus called: ("+getTimer()+" ms)");
for (var prop in infoObject) {
Debug.write("\t"+prop+":\t"+infoObject[prop]);
}
Debug.write('');
if ( infoObject.code == 'NetStream.Play.Stop' ) {
clearInterval(myDisplay.intervalID);
}
]]>
</method>
<method name="executeCallback">
parent.timeLabel.setText('Time:' + this.ns.time);
Debug.write('hello');
</method>
<method event="onload" name="handleLoad"><![CDATA[
Debug.write('onload');
this.nc = new NetConnection();
this.nc.connect(null);
this.ns = new NetStream(nc);
this.ns.onStatus = this.onStatus;
this.intervalID = setInterval(this, 'executeCallback', 500);
Debug.write(this.intervalID);
this.mc = getMCRef();
this.mc.theVideo.attachVideo(this.ns);
//mc.theVideo.attachVideo(Camera.get());
this.mc.theVideo.smoothing = true;
this.ns.play("tbot_high.flv");
]]>
</method>
</view>
<text name="timeLabel" x="50" y="${parent.myDisplay.y + parent.myDisplay.height + 10}">
</text>
</canvas>
There is some code in there to take a snapshot of a frame during playback as well.
I'll try to study that code ..
meanwhile from that earlier link I gave above
HQM wrote ..
SWF resources are treated differently depending on if they are loaded at compile time
(compiled into the app) or at runtime (using some variant of loadMovie).
You can look at the loader code for how resources and data are loaded at runtime.
It is not pretty though. That stuff is in the source distro under WEB-INF/lps/lfc/services/LzLoadQueue.as
and data/LzLoader.as and LzMediaLoader.as
(also uses transformers/LzMakeLoad.as).
At runtime resources are loaded into an empty container movieclip using loadMovie().
You may access that container movieclip. It may be instructive to poke around in the debugger with this flag set:
Debug.showInternalProperties = true
That will show you probably more than you want to know about the internals.
but how to use Debug.showInternalProperties to inspect imported movie?
jstretch
03-13-2006, 08:17 AM
woot!
<canvas width="500" height="500">
<debug x="0" y="50" height="450" width="500" />
<view id="test" width="200" height="50" oninit="${this.setSource('resources/test.swf')}" />
</canvas>
test.swf, created in flash 8, exported as flash 7 simply contains a text field which I found in the Debugger as instance22.
In Debugger type:
test.__LZmovieClipRef.lmc.instance22.htmlText = "Hello World"
Of course this doesn't do much good since dynamically it could be any instance#. So now how do we figure out what the objects in our loaded MCs are labeled?
Shelby
03-13-2006, 08:23 AM
You should be able to call getMCRef() against the view "test".
this.mc = this.getMCRef();
this.mc.htmlText = "Hello World"
More clues ..
the dump from the debugger above
$m0: «MovieClip#7| _level0.$m0»
$m1: «MediaLoadObj#8| test.swf (loaded)»
$m2: «MovieClip#9| _level0.$m2»
reminded me of this thread ..
accessing object in swf resource (http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=4233&highlight=%24m0)
jstretch
03-13-2006, 09:34 AM
thats much nicer thanks ;)
Originally posted by Shelby
You should be able to call getMCRef() against the view "test".
this.mc = this.getMCRef();
this.mc.htmlText = "Hello World"
edit:
However, we still have to reference the instance name:
test.getMCRef().instance22
jstretch
03-13-2006, 10:15 AM
I managed to call a function aswell:
Actionscript test.fla frame 1 layer 1:
function testFunction(str) {
return(str + " "+ str);
}
Laszlo Debugger:
test.getMCRef()
«MovieClip#125| _level0.$m1.lmc1»
«MovieClip#125| _level0.$m1.lmc1» {
__proto__: «Object#126| MovieClip.prototype»
_currentframe: 1
_opacity: «undefined»
_rotation: 0
_visible: true
_x: 0
_xscale: 100
_y: 0
_yscale: 100
cache: true
ccache: true
constructor: MovieClip
instance22: «TextField(12)#128| [...]»
lzr: swf7
lzt: media
proxied: true
testFunction: «Function#129| undefined#129»
timeout: 30000
txt: default text
url: http://localhost/laszlo_cct/src/resources/test.swf
}
«MovieClip#125| _level0.$m1.lmc1»
«Function#129| undefined#129» {
__proto__: «Object#130| Function.prototype»
constructor: Function
name: undefined#129
prototype: «Object#132| undefined#129.prototype»
}
«Function#129| undefined#129»
test.getMCRef().testFunction("hello")
"hello hello"
o.k. .. this thread has helped me to navigate to read "txt" field in embedded swf resource
by using .. viewid.getMCRef(); .. e.g. test.getMCRef();
I get .. _level0.$m0.lmc1
but now, from host openlaszlo view of resource, how can a value be written to the "txt" field in embedded swf resource?
perhaps by calling an embedded actionscript function as in your example?
jstretch
03-14-2006, 04:38 AM
Originally posted by d~l
o.k. .. this thread has helped me to navigate to read "txt" field in embedded swf resource
by using .. viewid.getMCRef(); .. e.g. test.getMCRef();
I get .. _level0.$m0.lmc1
but now, from host openlaszlo view of resource, how can a value be written to the "txt" field in embedded swf resource?
perhaps by calling an embedded actionscript function as in your example?
Two ways i've tested via debugger sofar:
- pass a variable to a function which in turn sets the textfield's value, in the flash swf function:
//if html textfield
path.to.txt.htmlText = "blah blah";
//else
path.to.txt.text = "blah blah";
- if the textfield sets the 'var' name(flash8) then all you have to do is set that variable and the textfield will assume that value. Eg. if var=myText, then in laszlo you can run:
//assuming everything is at the root level
test.getMCRef().myText = "blah blah blah";
I am trying to access methods in a movieclip test.swf imported as resource in deng_view.
Test.swf has a set of functions controlling another movie deng.swf.
The actionscript for test.swf is in test.as in attached zip.
So the hierarchy is .....
lzx canvas (deng_test.lzx)
------> load mc test.swf
----------->load mc deng.swf
If I run this command in debugger deng_view.getMCRef()
this is returned ..
deng_view.getMCRef()
«MovieClip#15| _level0.$m1.lmc1»
lzx>
note: this script in lzx code gives null .. why?
var mc = deng_view.getMCRef();
Debug.write("mc = " + mc);
...
now clicking on MovieClip#15
deng_view.getMCRef()
«MovieClip#15| _level0.$m1.lmc1»
lzx> Debug.inspect(«MovieClip#15| _level0.$m1.lmc1»)
«MovieClip#15| _level0.$m1.lmc1» {
btnReload: «ˇMovieClip!#17#18| _level0.$m1.lmc1.btnReload»
click: «Function#19| undefined#19»
dengcontainer_mc: «żmovieclip?#20| _level0.$m1.lmc1.dengcontainer_mc»
mcl: «object#21| {}»
mcScrollBar: «ˇMovieClip!#16#22| _level0.$m1.lmc1.mcScrollBar»
onClickHandler: «Function#23| undefined#23»
onLoadError: «Function#24| undefined#24»
onLoadInit: «Function#25| undefined#25»
onLoadXML: «Function#26| undefined#26»
onRender: «Function#27| undefined#27»
scroll: «Function#28| undefined#28»
}
«MovieClip#15| _level0.$m1.lmc1»
lzx>
so from lzx canvas how do I call the methods in test.swf .. and the other mc deng.swf
from debugger .. the path is ..
_level0.$m1.lmc1.deng_view.deng_container.deng_mc
e.g. call onloadInit() in test swf ...
this is the function in test.swf
function onLoadInit(mc:MovieClip) {
var deng:MovieClip = this.dengcontainer_mc.deng_mc;
trace("initDeng");
deng.addListener(this);
deng.setDocumentUri("sample.html");
deng.setSize(384, 400);
deng.render();
}
.......
Summary - I'm trying to call methods in test.swf which call methods in deng.swf.
This is the DENG API (http://deng.com.br/forum/viewtopic.php?t=85). I am trying to access/change attributes such as target XHTML page.
This recent thread (http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=5641) discusses DENG.
jstretch
03-17-2006, 05:20 AM
Originally posted by d~l
note: this script in lzx code gives null .. why?
var mc = deng_view.getMCRef();
Debug.write("mc = " + mc);
remove http: from the resource attribute
Thanks .. that now gives me a return for var mc .. _level0.$m1
but how do I now create a path to access these deng methods
deng.setDocumentUri("sample.html");
deng.setSize(384, 400);
to pass different target page, and size?
jstretch
03-17-2006, 06:08 AM
Here's one way:
deng_view.getMCRef().dengcontainer_mc.deng_mc.setS ize(100,100)
That works nicely .. thanks.
Now I can start to access the DENG methods from openlaszlo canvas to change properties of the rendered XHTML image.
sample code below .. but note that ..
* width change works .. but not height attribute ??
* changing document uri does not yet work (needs change to method).
_________________________________
Later edit .. inspecting test.as file (the actionscript for test.swf) it is clearer ..
the height of scrollbar is fixed at 400
// deng_mc.dom.uiDom.contentHeight is the total height of the root element
mcScrollBar.setScrollProperties(400, 0, this.dengcontainer_mc.deng_mc.dom.uiDom.contentHei ght - 400);
.. which probably prevents doc height resizing.
These all need to be arguments passed from openlaszlo canvas and then a recompile of test.as.
_________________________________
<?xml version="1.0" standalone="no"?>
<!DOCTYPE canvas SYSTEM "http://www.laszlosystems.com/lps/tools/lzx.dtd">
<canvas width="600" height="600" debug="true">
<view id="control" x="0" y="0" >
<button x="0" y="0" text="100x100" onclick="deng_view.getMCRef().dengcontainer_mc.deng_mc.setS ize(100, 100);"/>
<button x="100" y="0" text="400x400" onclick="deng_view.getMCRef().dengcontainer_mc.deng_mc.setS ize(400, 400);"/>
<button x="0" y="50" text="sample" onclick="deng_view.getMCRef().dengcontainer_mc.deng_mc.setD ocumentUri('sample.html');"/>
<button x="100" y="50" text="sample2" onclick="deng_view.getMCRef().dengcontainer_mc.deng_mc.setD ocumentUri('sample2.html');"/>
</view>
<view id="deng_view" x="100" y="100" width="400" height="400" resource="test.swf" >
<method event="oninit">
<![CDATA[
Debug.inspect(this);
]]>
</method>
</view>
</canvas>
More work to do .. to take the actionscript in test.as and build these functions into openlaszlo library to access methods in deng_mc.
This would eliminate the need to import test.swf as a container for deng.swf.
Claus Wahlers, Developer of DENG, has just joined the forum in this parallel thread (http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&postid=18370#post18370).
Also see update on deng_example posted at above thread .. as deng_example2.zip.
aquis
03-20-2006, 02:04 AM
So as much as I've understood up to now, I can create a swf on which I could pass a variable from within tbe PHP or HTML where I am embedding the swf !
CAN you please answer bellow for me and other beginners how to make that simple lzx (what to put into ) for example a simple view or window with a text which is passed from a test.htm?text=abcdefgh or how a lzx file should look in order to get the parameter from a php file ?
Thank you
Reply is in your other thread.
From now, it's probably best then to keep all further DENG related info in the other "DENG specific" thread :)
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.